Advertisement

Unknown, simple problem

Started by April 15, 2001 06:14 PM
2 comments, last by Poltras 23 years, 9 months ago
Simple problem, I''m sure some of you have hurt your head against the wall (like I did) and lose some coffeine on this... I have a beautiful class A, which has a pointer to class B. Class B, in return, does too have a pointer to a class B. Now what? The simplest problem of all earth: declaration of both class. I cannot do the following (if some of you thought of this.. ):
  
class A
{
   protected: B* Toto;
}

class B
{
   protected: A* Toto;
}
  
Because the compiler will hurry to tell you that class B doesn''t exists when it comes to class A. Then I need help. I just tried thingies like declaring a
  
class B;
  
before the declaration of class A, but it didn''t seem to work... I''m waiting (desparately) for an answer... Thanks
Now I know what I'm made of, and I'm afraid of it...
What a tricky question!!! I don´t think it is possible. One must come first ( "what came first the hen or the egg?" ).

good luck,



Zeblar Nagrim, Lord of Chaos
Advertisement
Just putting class B; before it works just fine for me... I have all my classes declared like that in my main.h so I never have to worry about that problem (which I did have cause my entities have a pointer to the map they''re on, and the map has a pointer to all the entities on it) when including one class in a different one. You could try putting extern class B; in a header file and including it just to see what happens. That''s what I did at first, which worked, but then the compiler said extern wasn''t doing anything so I removed it, but you might as well give it a shot.



-Deku-chan

DK Art (my site, which has little programming-related stuff on it, but you should go anyway^_^)
Forward declarations ( class B; ) should work to fix it.


If that''s the actual code in the post, you need semicolons after the class closing braces...

This topic is closed to new replies.

Advertisement