Jump to content
  • Advertisement

Archived

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

PSioNiC

C++ Class question

This topic is 6348 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 thought i already posted this before but i can''t find it) If you have:
  

class FOO {
  public:
    BAR MyBar;
}

class BAR {
  public:
    FOO MyFoo;
}

  
the program will crash when it hits
  

BAR MyBar;

  
because the BAR class has not yet been defined. Is there some way how I could declare classes at the top (like a function declaration for classes), or is there another way around this?

Share this post


Link to post
Share on other sites
Advertisement
Well, you can use forward declarations:

  
class foo;
class bar;

class foo
{
...
};

class bar
{
...
};


However, in the example you gave, I don't see how the compiler could ever instantiate either of the objects. One depends on the other which depends on the one, and so forth. But if those members were pointers to foo and bar, that'd be fine.

Edited by - merlin9x9 on July 26, 2001 5:41:51 PM

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.

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!