在成员函数中调用析构函数

Dar*_*bik 5 c++ destructor new-operator

假设我有一个这样的类:

#include <new>
struct thing {
  thing() = default;
  void foo()
  {
    this->~thing();
    new (this) thing();
  }
};
Run Code Online (Sandbox Code Playgroud)

是这样调用析构函数然后使用放置新定义的行为重建对象?

归档时间:

查看次数:

314 次

最近记录:

7 年,7 月 前