class definition position?

C

cylin

Dear all,

For example,

class CA;

class CB {
public:
int m_iY;
CA m_oCA;
};

class CA {
public:
int m_iX;
};

I use BCB compiler, but it says "undefined structure CA".
The style is standard, why it can't compile well?
I know if I put full definition of CA before CB, it's ok.
Thanks for your answer.

Regards,
cylin.
 
J

Josephine Schafer

cylin said:
Dear all,

For example,

class CA;

class CB {
public:
int m_iY;
CA m_oCA;
};

class CA {
public:
int m_iX;
};

I use BCB compiler, but it says "undefined structure CA".
The style is standard, why it can't compile well?

Because the compiler does not know the size of CA.
A forward declarartion only tells the compiler that such a class
exists somewhere but does not tell it's size which is required here.
Else use a pointer/reference to CA in CB.

HTH.
 

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
474,139
Messages
2,570,805
Members
47,351
Latest member
LolaD32479

Latest Threads

Top