[基础] 重载的时候什么时候用引用&

时间:2021-02-02 00:48:55

一般返回值还要继续被处理,而不仅仅是得到其值的时候,返回引用&

一般有[], =, ++, --, 还有输入输出运算符<<, >>

Classtype &operator++() {
++this->num;
return *this;
}
//调用前置版本
const Classtype operator++(int) {
Classtype old(*this);
//++this->num;
++*this
return old;
}

相关文章