I'd like to use pimpl to reduce dependencies as follows:
// myClass.h
#include <memory>
class myClass {
public:
myClass();
private:
struct myStruct;
std::auto_ptr<struct myStruct> m_pimpl;
};
// myClass.cpp
#include "myClass.h"
struct myClass::myStruct {
// ...details
};
myClass::myClass() : m_pimpl(std::auto_ptr<myStruct>(new myStruct()))
{ }
This compiles just fine, until I try to use myClass elsewhere. At
this point, I get warnings like:
"deletion of pointer to incomplete type 'myStruct'; no destructor
called"
I guess I understand why this happens, and it's fixed by declaring a
destructor for myClass and defining it in the .cpp file. It just irks
me that I need to define a blank destructor (the same thing the
compiler should generate) to make this work. Googling this issue, I
find http://www.gotw.ca/publications/using_auto_ptr_effectively.htm,
in which Mr. Sutter demonstrates this same code and adds the comment:
"In fact, if there's no other reason for explicitly writing a
destructor, we don't need to bother with a custom destructor at all
any more."
I'm seeing that this is not the case. Unless (likely) I am doing
something wrong. Thoughts?
Thanks in advance,
Ryan
Is there a workaround for this issue? I know it's only a few more
lines of code
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


|