为什么没有调用析构函数
Why is the destructor not called?
这是合乎逻辑的,在堆栈上创建对象…返回对象的副本,删除原始对象
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!
为什么在第二个操作符重载方法中没有调用析构函数?
您看到的是编译器没有通过执行返回值优化来创建临时对象。
没有调用析构函数,因为编译器可以在这里执行"返回值优化"。
相关文章:
- 析构函数调用
- 在具有向量的类构造函数中进行析构函数调用
- 从 c++ 中派生类的析构函数调用虚函数
- C++析构函数调用两次,堆栈分配的复合对象
- C++ 在析构函数调用之前删除的动态成员数组
- 析构函数调用c++中的一个向量
- Singleton模式中的手动析构函数调用:调用多次
- 从内部类的析构函数调用虚拟函数
- 与 boost odeint 集成期间的析构函数调用
- 堆栈展开如何与析构函数调用有关?
- C++:优化析构函数调用
- 以逗号分隔的表达式中的析构函数调用
- GCC 9.1 返回 void& 作为显式析构函数调用的结果类型。这是一个错误吗?
- 从C++中的虚拟析构函数调用虚拟方法
- 从指针返回对象时出现意外的析构函数调用
- 使用 decltype 显式析构函数调用
- C++析构函数调用了错误的对象
- 了解虚拟函数和析构函数调用
- 多重继承析构函数调用他自己和父析构函数?c++
- 析构函数调用表单不适当的库