随笔

1.看是否修改算子,++,--,+=,-=

加const(参数表里)

2,对自己是否修改

3.左值||对自己修改还是新的对象

class Test
{
private:
    int x;
public:
    const Test& operator+(Test t){return *this;}
    //返回值不可修改
    //对自己本身进行修改
    //返回值可做左值
    Test operator+(Test t)const{}
    //本身对象是不可修改的
    //const是加在*this上面的
    Test operator+(const Test t){}
    //传入的算子不能改变
};

  

原文地址:https://www.cnblogs.com/-Asurada-/p/10770724.html