I’m using boost::scoped_ptr and a forward declaration in a header file:
//Bar.h
class Foo;
class Bar;
{
private:
boost::scoped_ptr<Foo> _foo;
};
I don’t implement my own destructor since the smart pointer will do the job.
I include this header file in multiple translation units and not all of them include the Foo definition. When trying to compile I get an error that scoped_ptr is deleting a pointer to incomplete type Foo.
Everything is fixed easily if I declare an empty destructor in Bar.h and implement it in Bar.cpp.
However I got the same error if the destructor is implemented in a header file.
So the question is: in which translation units do implicitly defined methods go?
The question is not correctly formulated. What you want to know is
What translation unit holds implictly defined special member functions?
[That’s a mouthful]. And the answer is in each and every translation unit that uses (odr-uses) them.
For your particular use case, and because the
scoped_ptrdestructor requires the type to be complete, you have no option but to declare the destructor ofBar, and define it even if empty in a translation unit that has a full definition ofFoo.Alternatively, you could use a different type of smart pointer that does not have that restriction.