第一种情况:-
Void operator=(const Test& obj)
{
if(this != &Obj)
{
x=new int;
*x=*obj.x;
}
}
第二种情况:-
Test& operator=(const Test& obj)
{
if(this != &Obj)
{
x=new int;
*x=*obj.x;
}
return *this;
}
以上两个用于赋值运算符重载的代码都可以正常工作。那么为什么在第二种情况下,当正常的void作为return时,为什么还需要返回类型为“ Test&”呢?