Skip to main content
gamedev.net
🔒 Locked

Stupid class problem

Started by VanKurt 2 replies 300+ views
Original Post
VanKurt
VanKurt
Hi there! I'm having a little problem bothering quite some time ;-) Look at this: class ClassA { public: ClassB myB; }; class ClassB { public: ClassA myA; }; This code won't work because ClassB isn't defined when ClassA gets compiled... is there a way to ceate somekind of "prototypes" for classes? Thank's a lot!
SiCrane
SiCrane
Assuming this is C++, you can't recursively store variables by value like that; it would require infinite size for each of the classes. You can store pointers, and if you use pointers you can create forward declarations for the classes. ex:
class ClassB;class ClassA {  public:    ClassB * myB;};
dimebolt
dimebolt
class ClassB;class ClassA{public:	ClassB *myB;};class ClassB{public:	ClassA myA;};

You will have to use pointers, but it will work like this.

Tom

EDIT: D'oh :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.