Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have below Code
C++
class B;
class A
{
	B b;
};
class B
{
	A a;
};

But I get Error <<'A::b' uses undefined class 'B'>>

How I can to use template for solve it
Posted
Updated 23-Jun-15 14:10pm
v2
Comments
barneyman 23-Jun-15 19:35pm    
because it does!

google for 'circular dependency' and you'll find some solutions

1 solution

If it was possible, you could not initialize the instances of any of these classes, because it would recursively create infinite number of A and B instances. But you could have a pointers of these types as instance members. You should avoid the situation with infinite recursive instantiation, even with pointers. For example, if a and b were pointers, a.B and b.A could point to each other.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900