为什么不调用析构函数?
问题描述:
这是合乎逻辑的,在栈上创建对象...对象的副本返回,原来被删除为什么不调用析构函数?
Box operator +(const Box& box) const
{
Box b = Box(this->num + box.num);
return b;
} // destructor called!
为什么在这种情况下是不同的过程?
Box operator +(const Box& box) const
{
return Box(this->num + box.num);
} // destructor not called!
为什么在第二个运算符重载方法中不调用析构函数?
你是如何使用这个功能的?你分配结果? – 2013-04-09 19:00:38
Box box1 = box2 + box3; – 2013-04-09 19:01:16
查找“返回值优化”。 – Angew 2013-04-09 19:02:14