Is std::unique_ptr required to know the full definition of T?

前端 未结 9 1533
小鲜肉
小鲜肉 2020-11-22 07:47

I have some code in a header that looks like this:

#include 

class Thing;

class MyClass
{
    std::unique_ptr< Thing > my_thing;
};
         


        
9条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-22 07:48

    The compiler needs the definition of Thing to generate the default destructor for MyClass. If you explicitly declare the destructor and move its (empty) implementation to the CPP file, the code should compile.

提交回复
热议问题