By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,389 Members | 1,881 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,389 IT Pros & Developers. It's quick & easy.

class definition position?

P: n/a
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.
Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"cylin" <cy***@avant.com.tw> wrote in message
news:bh************@ID-154203.news.uni-berlin.de...
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.
--
With best wishes,
J.Schafer
Jul 19 '05 #2

P: n/a
Thanks all, I learn much.

Regards,
cylin.
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.