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

前端 未结 9 1528
小鲜肉
小鲜肉 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 08:08

    This isn't implementation-dependent. The reason that it works is because shared_ptr determines the correct destructor to call at run-time - it isn't part of the type signature. However, unique_ptr's destructor is part of its type, and it must be known at compile-time.

提交回复
热议问题