这是合乎逻辑的,在堆栈上创建对象...对象的副本返回,原始被删除
Box operator +(const Box& box) const
{
Box b = Box(this->num + box.num);
return b;
} // destructor called!
Run Code Online (Sandbox Code Playgroud)
在这种情况下为什么这个过程不同?
Box operator +(const Box& box) const
{
return Box(this->num + box.num);
} // destructor not called!
Run Code Online (Sandbox Code Playgroud)
为什么在第二个运算符重载方法中没有调用析构函数?