I have a class like this:
class Inner;
class Cont
{
public:
Cont();
virtual ~Cont();
private:
Inner* m_inner;
};
in the .cpp, the constructor creates an instance of Inner
with new
and the destructor delete
s it. This is working pretty well.
Now I want to change this code to use auto_ptr
so I write:
class Inner;
class Cont
{
public:
Cont();
virtual ~Cont();
private:
std::auto_ptr<Inner> m_inner;
};
Now, the constructor initialized the auto_ptr
and the destructor does nothing.
But it doesn't work. the problem seem to arise when I'm instantiating this class. I get this warning:
warning C4150: deletion of pointer to incomplete type 'Inner'; no destructor called
Well, this is obviously very bad and I understand why it happens, The compiler doesn't know about the d'tor of Inner
when instantiating the template of auto_ptr<Inner>
So my question: Is there a way to use auto_ptr
with a forward declaration like I did in the version that uses just plain pointers?
Having to #include
every class I declare a pointer to is a huge hassle and at times, just impossible. How is this problem usually handled?