Completing type of the class

M

mscava

I have 2 classes - Widget and Dialog. Dialog IS Widget. It contains
vector of Widgets. Widget get passed pointer to Dialog in constructor.
So both classes need to know about themselves.

//------------------------------------------------------------------
Dialog.hpp
//------------------------------------------------------------------
#include "Widget.hpp"

class Dialog : public Widget
{
vector<Widget*> widgets_;
};
//------------------------------------------------------------------
Widget.hpp
//------------------------------------------------------------------
class Dialog;

class Widget
{
Widget( Dialog* parent );
};

The problem is that whenever I try to declare Dialog variable compiler
outputs that Dialog has incomplete type... Any suggestions?
 
V

Victor Bazarov

I have 2 classes - Widget and Dialog. Dialog IS Widget. It contains
vector of Widgets. Widget get passed pointer to Dialog in constructor.
So both classes need to know about themselves.

//------------------------------------------------------------------
Dialog.hpp
//------------------------------------------------------------------
#include "Widget.hpp"

class Dialog : public Widget
{
vector<Widget*> widgets_;
};
//------------------------------------------------------------------
Widget.hpp
//------------------------------------------------------------------
class Dialog;

class Widget
{
Widget( Dialog* parent );
};

The problem is that whenever I try to declare Dialog variable compiler
outputs that Dialog has incomplete type... Any suggestions?

In the code above there is nothing to suggest the behaviour you described.

Try to ensure that 'Widget' class is defined before 'Dialog' class. You
can do that by tweaking the order in which your headers are included.

I also strongly recommend adding double inclusion guards to your headers.

V
 
M

mscava

In the code above there is nothing to suggest the behaviour you described.

Try to ensure that 'Widget' class is defined before 'Dialog' class. You
can do that by tweaking the order in which your headers are included.

I also strongly recommend adding double inclusion guards to your headers.

V

Thank you very much... I've found the mistake. You were right, the
code was ok, but I have forgotten to include Dialog.hpp into main...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top