The unique_ptr destructor must know the full definition of AImpl as it removes it. So the question is, where is the unique_ptr destructor unique_ptr ? This is a template, so the question is about the instantiation point.
The destructor is created when it is first used. Both the constructor and the destructor of the containing class use it (the constructor needs it if its body throws an exception). Thus, the unique_ptr destructor is created where the constructor or destructor of A , whichever comes first.
If you default these special members, they are generated immediately after the class body, that is, in the header, where the size of AImpl unknown.
If you instead declare them in a class and then put the definitions (you can =default these definitions) in .cpp , after the AImpl fully defined, a AImpl instance is created there.
Sebastian redl
source share