Advertisement Jump to content
Sign in to follow this  
NIm

circular class dependancies

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

I am writing a tile based game in c++, intended to be along the lines of nethack and angband. I've gotten to the point where I am implementing monsters, an I've run into a problem. I need the player to interact with the map, so I have a pointer to map in my monster class, however, I also need a particular map square to point to the monster that is sitting on it, as well as giving the map a list of monsters to update each turn. I realize that I could make map a global variable, but I hear that that' a bad idea, and it may interfere later when I try to have multiple maps. Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
Assuming you are talking about C++ you can use forward class declarations:

class CMonster;

class CTile
{
protected:

CMonster* m_pMonster;
};

class CMonster
{
protected:

CTile* m_pTile;
};


Greetz,

Illco

Share this post


Link to post
Share on other sites
Thank you so much! I was thinking about something like that, but didn't know how to implement:)

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!