【发布时间】:2020-04-10 00:26:52
【问题描述】:
好吧,我的班级中有重要的析构函数。
我可以这样做吗:
Foo& Foo::operator=(Foo&& from) {
~Foo()
// Copy the stuff and cleanup "from"
}
我想要实现的是避免代码重复。
另外,我可以写一些清理函数,但是如果我可以调用析构函数,那又是为了什么呢?
【问题讨论】:
-
如果调用析构函数,对象不复存在,需要在其位置上构造一个新对象。您可以为此使用带有移动构造函数的placement new。
标签: c++11 destructor move-semantics