In order to use an incomplete type with a smart pointer such as boost::scoped_ptr
, one must explicitly define an empty destructor for the parent class in the corresponding CPP file. Example:
// H file
class Foo
{
public:
~Foo();
private:
class Pimpl;
boost::scoped_ptr<Pimpl> pimpl_;
};
// CPP file
class Foo::Pimpl {};
Foo::~Foo() {}
Where exactly does the compiler place the instantiation of boost::scoped_ptr
's destructor? I'm trying to visually imagine where it would be in either of these source files, as if I had explicitly defined scoped_ptr's destructor myself. Is it reasonable to imagine it this way?
I know that template methods and classes aren't instantiated for a type until it is used with that type, but I'm trying to think about it structurally now, and where the compiler would place it if it actually hand-wrote it. This will help me get a better understanding of how such techniques (like the one above) are able to be used.
Also I'm not sure if the entire definition of a template class is instantiated or only the relevant parts of it, as they are used. In other words, is it possible for only part of boost::scoped_ptr
's entire definition to exist?