zoukankan      html  css  js  c++  java
  • const修饰的成员函数

    #include <iostream>
    using namespace std;
    
    class Cube
    {
    public:
        void SetL(int l)
        {
            m_L = l;
        }
    
        int GetL() const   //只有用const修饰的方法,compareCube才能用const做形参
        {                //如果没有const 修饰,就没法保证成员函数里是否修改了成员属性
            return m_L;
        }
    
    private:
        int m_L; //
        int m_W; //
        int m_H; //
    }
    
    bool compareCube(const Cube &cub1,const Cube & cub2) 
    {
        return cub1.GetL() == cub2.GetL()
    }
    
    int main()
    {
    
    }
  • 相关阅读:
    2021/6/17学期总结
    2021/6/16申请加分
    2021/6/15
    2021/6/14
    2021/6/11
    2021/6/10
    2021/6/9
    2021/6/8
    2021/6/7
    2021/6/5读书笔记
  • 原文地址:https://www.cnblogs.com/yifengs/p/15162471.html
Copyright © 2011-2022 走看看