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

Bi-directional link between two class

P: n/a
Hi all,

I encounter a problem: I want to define two class, A has a point to B
and B also has a point to A. Something like a bi-directional link list.
But It has compile error.

//---code-------
class A
{
...
B* b;
}

class B
{
...
A* a;
}
//--------------
The error message is B is a unknown type.

Best regards,
Robert

Jul 28 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Robert wrote:
The error message is B is a unknown type.


That's because at the point of declaration of A::b, class B is unkown.
You have to forward-declare it:

//---code-------
class B;

class A
{
...
B* b;
};

class B
{
...
A* a;
};
//--------------
--
Matthias Kaeppler
Jul 28 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.