我有一个自定义课程。我们就叫它苹果吧。我这样重载加法运算符:
apple apple::operator+(const apple & other)
{
return apple
(
this->x + other.x,
this->y + other.y,
this->z + other.z
);
}
它工作得很好......直到我尝试添加两个 const 苹果。
const apple apple1;
const apple apple2;
auto apple3 = apple1 + apple2;
给我一个错误'没有运算符“+”匹配这些操作数操作数类型是:const apple + const apple'
添加 const 对象有什么技巧吗?