Accessing classes before they are "made"

Started by
12 comments, last by Drakon 20 years ago
Replace ''ClassName'' with ''class ClassName'' where you get errors.
Advertisement
You can''t have a recursive containment, as that would require infinite storage (think about it).

What you can have is recursive references, using a pointer or a C++ reference.

In this case you can partially declare a class:

class B; // Tells compiler "Class B will exist"class A { private: B *bptr; public: void doSomething();};class B { private: A *aptr; // etc} 
Yeah, after I thought about it I changed them to pointers.
"Go for the eyes, Boo, go for the eyes!"
This circular dependency is a bad thing™, either you should think up an interface that Room can implement (that both Room and Object knows about) or you might want to go crazy and look up the observer-pattern.

This topic is closed to new replies.

Advertisement