jeudi 3 décembre 2015

invalid application of 'sizeof' to an incomplete type using unique_ptr, fixed with empty dtor. What?

I am Pimpling off the class STFT. Compiles just fine with this in the header . .

class STFT; // pimpl off to prevent point name clash

class Whatever
{
private:
    STFT* stft;

and this in the implementation . .

Whatever::Whatever() : stft(new STFT()) {
// blah blah
}

Whatever::~Whatever() {
    delete stft; // pure evil
}

However, switching to std::unique_ptr<STFT> stft; over the raw pointer in the header, and removing the dtor I get

error: invalid application of 'sizeof' to an incomplete type 'STFT' static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");

But then if I simply supply an empty dtor Whatever::~Whatever(){}. It compiles fine. This has me completely stumped. Please fill me in on what this meaningless dtor is doing for me.

Aucun commentaire:

Enregistrer un commentaire