On 4/29/05, Philippe Mori
And another pitfal with both auto_ptr and shared_ptr (at least on VC7.1 compiler) is if you don't provide expicit destructor, the generated destructor will try destroy the auto_ptr, which in its turn will try to destroy you pimpl via imcomplete pointer, therefor not calling destructor. Fortunately compiler at least gives a warning: "deletion of pointer to incomplete type 'TestClass::PrivateData'; no destructor called"
I suppose that a complete type is required to instanciate shared_ptr destructor and any function that will destroy the pointee.
I was thinking that shared_ptr does ensure by itself that a complete type is used (contrary to auto_ptr) so that the type must be complete to compile properly. Do you just have a warning meaning that on older compiler someone might not even notice the problem.
IMO, the fact that shared_ptr accept incomplete type but require a complete type is what make it interesting for pimpl.
Philippe
I've re-checked the issue with incomplete type, and I see I was wrong. For such class (class without destructor explicitly instantiated): class TestClass { public: TestClass(); // Note there is no destructor // virtual ~TestClass(void); TestClass(const TestClass& other); TestClass& operator=(const TestClass& other); private: class PrivateData; // std::auto_ptr<PrivateData> pd; // boost::scoped_ptr<PrivateData> pd; boost::shared_ptr<PrivateData> pd; }; The results was: auto_ptr - compiled with warning about destroying incomplete type scoped_ptr - failed to compile (thanks to "checked_delete") shared_ptr - compiled and worked - the destructor of TestClass::PrivateData was called (don't know how it works). -- Best regards, Zigmar