Hello there,
Im new in C++ programming, and i ve some troubles that ive never seen in other languages.
I ve two classes, and each one has a pointer to the other:
class C1{
public: C2* pointerC2;
}
class C2{
public: C1* pointerC1;
}
Well, the compiler cannot parse it, i think its cause C2 is not visible for C1 in compiling time. In fact, for C1, C2 its not yet declare.
What can i do, please?
Thank you, and excuse my very bad english.
How to declare two classes that have a pointer n between?
Started by radel, Apr 18 2008 09:42 AM
3 replies to this topic
#1
Posted 18 April 2008 - 09:42 AM
|
|
|
#2
Posted 18 April 2008 - 11:33 AM
Use a forward declaration.
[FONT="Fixedsys"][COLOR="Blue"]class C2; // forward declaration[/COLOR]
class C1{
public: C2* pointerC2;
}[COLOR="Red"];[/COLOR]
class C2{
public: C1* pointerC1;
}[COLOR="Red"];[/COLOR][/FONT]
#3
Posted 19 April 2008 - 11:00 AM
dcs said:
Use a forward declaration.
[FONT="Fixedsys"][COLOR="Blue"]class C2; // forward declaration[/COLOR]
class C1{
public: C2* pointerC2;
}[COLOR="Red"];[/COLOR]
class C2{
public: C1* pointerC1;
}[COLOR="Red"];[/COLOR][/FONT]Edit: in both haeders!


Sign In
Create Account

Back to top









