Accessing classes before they are "made"
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:
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}
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
Popular Topics
Advertisement