mardi 8 mai 2018

Invalid application of ‘sizeof’ to incomplete type - unique_ptr with defined destructor

I don't know why this isn't working. I'm doing the exact same thing in another class, and there's no issue there. But for some reason, in this program it's not working. I can't see the problem, can anyone spot it? The following code is just an example, but the actual code is the exact same with longer names and a couple of member functions.

Header:

#ifndef BC_class
#define BC_class

#include <memory>

class DB;

class BC {
private:
    std::unique_ptr< DB > dbConn{nullptr};

public:
    BC( );
    ~BC( );

};

#endif

CPP:

using namespace std;

#include "BC.h"
#include "DB.h"

BC::BC( ) {
    dbConn.reset( new DB( ) );
}

BC::~BC( ) {
    // Nothing to see here
}

Error:

/usr/include/c++/7/bits/unique_ptr.h: In instantiation of ‘void std::default_delete<_Tp>::operator()(_Tp*) const [with _Tp = DB]’:
/usr/include/c++/7/bits/unique_ptr.h:268:17:   required from ‘std::unique_ptr<_Tp, _Dp>::~unique_ptr() [with _Tp = DB; _Dp = std::default_delete<DB>]’
BC.h:21:48:   required from here
/usr/include/c++/7/bits/unique_ptr.h:76:22: error: invalid application of ‘sizeof’ to incomplete type ‘DB’
static_assert(sizeof(_Tp)>0,

Aucun commentaire:

Enregistrer un commentaire