我正在将类STFT
实现为Pimpl模式。在头文件中加入以下代码后可以通过编译:
class STFT; // pimpl off to prevent point name clash
class Whatever
{
private:
STFT* stft;
并且在实现中:
#include "STFT.h"
Whatever::Whatever() : stft(new STFT()) {
// blah blah
}
Whatever::~Whatever() {
delete stft; // pure evil
}
然而,将头文件中的原始指针切换为std::unique_ptr<STFT> stft;
并删除析构函数后,我得到以下错误:
error: invalid application of 'sizeof' to an incomplete type 'STFT' static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
但是,如果我只提供一个空析构函数Whatever::~Whatever(){}
,那么它就可以编译通过。这让我感到非常困惑。请告诉我这个没有意义的析构函数对我的作用是什么。