Thursday 15 August 2013

class - Co-existent classes in C++ -


What do I need to do to create two classes, which uses each other.

For example:

class A has the type of object type class B , and square b type of objects in class A

But, when I compile, this happens: "Error: ISO C ++ does not have any type of 'map' With no declaration forbidden "

I modified my classes,

Probably, this is a basic question, but I do not know the keyword to search on Google ...

Code:

Cell.h:

  class cell {public: map * map; }   

Map.h:

  class map {public: cell * cell; }    

if a class in class A Is b and square b is also a square a , then you can not do that.

  class B; // Only the next announcement compiler of the name does not know // How much space a B still needs Class A {Private: BB; // failed because we do not know what B is yet. }; Class B {Private: AA; };   

Even if this works, there will be no way to prepare any examples.

  b b; // allocates the space for a B1, which requires the allocation of A for its A, which requires the allocation of its B, which is allocated for its A // and the space on it. It needs to be ...   

There may be indications (or references) to each other.

  class B; // Next Declaration tells the compiler to expect B type. Class A {Private: B * B; // Allocates space for only one indicator which is always known / regardless of type. }; Class B {Private: A * A; };    

No comments:

Post a Comment