【发布时间】:2015-10-07 20:17:44
【问题描述】:
class A
{
public:
int v;
A * p;
A& operator*(const A& a)
{
return this->v*a.v// here is a red line under this say error initial value of reference to non-const must be an value
}
~A()
{
this;
}
};
int main()
{
A a;
a.p = new A;
delete a.p;
return 0;
system("pause");
return 0;
}
重载 * 运算符我不能用它来表示对象本身。为什么会这样。
【问题讨论】:
-
它是二元运算符(乘法) - 不是指针解引用。
-
哦。是的。你是对的。
标签: c++ operator-overloading operators