我只是想超載+運營商,我得到這個編譯器警告C++編譯器警告 - 返回局部變量
reference to local variable 'tmp' returned
下面是超載
const Int& Int::operator+(const Int& p) const
{
Int tmp = value + p.value;
return tmp;
}
這裏的代碼是類
class Int{
int value;
public:
Int() {} // default constructor
Int(int v) : value(v) {}
Int& operator=(const Int&);
const Int& operator+(const Int&) const;
};