Pimpl with unique_ptr : Why do I have to move definition of constructor of interface to “.cpp”?
问题 The code would work file as long as I don't move the definition of constructor (of B ) to the header B.h . B.h class Imp; //<--- error here class B{ public: std::unique_ptr<Imp> imp; B(); //<--- move definition to here will compile error ~B(); //// .... other functions .... }; B.cpp #include "B.h" #include "Imp.h" B::B(){ } ~B::B(){ } Imp.h class Imp{}; Main.cpp (compile me) #include "B.h" Error: deletion of pointer to incomplete type Error: use of undefined type 'Imp' C2027 I can somehow