Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

UK_Gamer

mutually recursive classes

This topic is 5305 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

Hi, I have successfully implemented a basic A* search program in Java, and am now trying to port it to C++. The problem is my node and nodelist classes in java. Node class holds the data at that node, and a nodelist of nodes connected to this node. Nodelist class holds a nodelist of nodes connected to this list, as well as the node at the top of this list. Having two classes use each other is fine in java, but in C++, one class can''t compile until the other one is compiled, and vice-versa. Is there a way round this problem?

Share this post


Link to post
Share on other sites
Advertisement
Forward declarations only work if you''re using pointers, or otherwise don''t need the actual definition of the class, only the name.

Share this post


Link to post
Share on other sites
Yes, but he needs to be using a pointer in at least one of the classes anyway.

Share this post


Link to post
Share on other sites
quote:
Original post by psykr
Forward declarations only work if you''re using pointers, or otherwise don''t need the actual definition of the class, only the name.


For it to be logically possible (realizing that we don''t use quantum computers) for it to work in any language (he said it worked in java) one of the classes must be restricted to merely having a pointer to the other.

______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________

Share this post


Link to post
Share on other sites
Pointers are the solution thanks.

(Java only uses pointers I believe which is why it worked originally)

Share this post


Link to post
Share on other sites

  • 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!