Jump to content
  • Advertisement

Archived

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

DanG

classes including each other, anyway around?

This topic is 5699 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 currently have two classes in my Tetris clone. One is Field, representing the play space, and the other is block, representing a single square area. Problem is each has a reference to the other and the compiler doesn''t like it. Here is what it looks like: // Field.h class Field { vector > m_Field; }; // Block.h class Block { Field & m_rField; } Problem is that to define one requires the other, so I can''t seem to get the compiler to relize the two exist. Any ideas?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Read up on forward declaring and friends.

Share this post


Link to post
Share on other sites
one way would be:


  
class A;

class B
{
private:
A* a;
};

class A
{

};


This would be called forward declaring , mentioned by AP.

Crispy

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!