forward declaration

V

Vince

Hi,

I have two classes that are mutually included So I Use forward declaration
and it works fine as long as I declare a pointer:

In WorkerThreadDemoDlg.h :


//forward declaration
class CMyThread;

class CWorkerThreadDemoDlg : public CDialog
{
public:
CWorkerThreadDemoDlg( CWnd* pParent = NULL ); // standard constructor

protected:
CMyThread* m_pCMyThread;
....
}

if I want to replace CMyThread* by a CMyThread it doesn't compile even if my
implementation I am not even using it.
 
V

Victor Bazarov

Vince said:
I have two classes that are mutually included So I Use forward declaration
and it works fine as long as I declare a pointer:

In WorkerThreadDemoDlg.h :


//forward declaration
class CMyThread;

class CWorkerThreadDemoDlg : public CDialog
{
public:
CWorkerThreadDemoDlg( CWnd* pParent = NULL ); // standard constructor

protected:
CMyThread* m_pCMyThread;
...
}

if I want to replace CMyThread* by a CMyThread it doesn't compile even if my
implementation I am not even using it.

Of course it doesn't. To know how big an object of 'CWorkerThreadDemoDlg'
should be, the compiler needs to know the size of every subclass and every
member object. If you don't have the definition of 'CMyThread' available
to the compiler, it can't figure out the size of 'CWorkerThreadDemoDlg'.

What did you expect, magic?
 

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,780
Messages
2,569,608
Members
45,249
Latest member
KattieCort

Latest Threads

Top