Quote: "
The entity handler is only used by the main.cpp file, and only one instance is created (which is probably why JTK suggested using a Singleton object...), so I suppose making that instance global in the main.cpp file and referencing it as extern in any necessary classes down the line would allow me to have access to it.
"
This will work so long as the instance is a pointer; that is, created with new (having the *); otherwise, the entirety of the class definition would be required...
Hence:
.h of Using class:
class UsedClass; /* forward declaration */
class UsingClass {
protected: /* or private or public */
UsedClass *used; // OK...
protected: /* or private or public */
UsedClass used; // Error... Entirety of UsedClass must be defined by now...
};
Or, if extern is used:
class UsedClass; /* forward declaration */
extern UsedClass *g_pUsedClass; // Ok...
extern UsedClass g_UsedClass; // Error...
Unless #include "UsedClass.H" is added to the header file in which the forward declarations would not be needed...
So, if you're using pointers to those classes, then you can disregard everything I've been saying...
I myself don't use pointers unless I have to (pointer indirection costs cpu time) - so I try to avoid them whenever possible...
Additionally, I try to avoid globals too, because I don't want to inadvertantly corrupt a global state - hence my use of singletons. However, when using a singleton, I am explicitly stating as such with the CSingleton:: reference before the actual call...
Personal preference, I suppose...
JTK
NOTE:
Wikipedia, btw, has several explicit C++ examples for you... I am only trying to offer a suggestion as to how to achieve your final goal - making the program work, without re-engineering your current structure. You can, of course, follow the global variable route, but it too has its drawbacks...