Jump to content
  • Advertisement
Sign in to follow this  
qqicq

How to interact between 2 classes

This topic is 2662 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[color=#1C2837][size=2]Hi all,

[color=#1C2837][size=2]I have a class, say A and another class B.

[color=#1C2837][size=2]In class A, I have a method C. inside this method, I will call method D from B
[color=#1C2837][size=2]ie: A::C()
{







[color=#1C2837][size=2] b.D(A* a) // b is intance of B
[color=#1C2837][size=2]}
[color=#1C2837][size=2]

[color=#1C2837][size=2]But as you see, the method D need a parameter which is a pointer of class A
[color=#1C2837][size=2]

[color=#1C2837][size=2]How can I do that?
[color=#1C2837][size=2]

[color=#1C2837][size=2]The header files sequence cannot provide me this way to program!
[color=#1C2837][size=2]

[color=#1C2837][size=2]Thanks all,
gogogo
[color="#1c2837"]

Share this post


Link to post
Share on other sites
Advertisement
Sorry...May be my expression is not good enough...

ok I have 2 classes, one is called A and another is called B.
I have 2 pairs of header and cpp files, A.h, A.cpp, B.h, B.cpp

In class A, I have a method C. Within the method C, I call method D which declare in class B
eg:

void A::C(B* b)
{
b->D(this);
}

which means that C() need to pass a pointer of B and D() need to pass a pointer of A.

The question is, how can I do that?
Because I cannot compile my code since the header file cannot recognize the classes.

eg: If I include A.h first in B.cpp, A.h cannot recognize the class B and vice [font=arial, sans-serif][size=2]versa[/font].

Thanks

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!