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

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

    The full definition of the Thing is required at the point of template instantiation. This is the exact reason why the pimpl idiom compiles.

    If it wasn't possible, people would not ask questions like this.

提交回复
热议问题