In my project, I have a few engines (particleEngine, cutsceneEngine, inputEngine etc...). For each one, there is only once instance; however, there are times when (lets say) the graphicsEngine needs to be aware of the particleEngine. So what I did was make a .h and .cpp file for every "engine" (only about 6) and then I would put:
#include "GlobalEngineNeeded.h"
and each GlobalEngineNeeded.h would look something like this:
#ifndef EG_GlobalEngineNeeded
#define EG_GlobalEngineNeeded
#include "EngineNeeded.h"
extern EngineNeeded *instanceOfThisEngine;
#endif
and each GlobalEngineNeeded.cpp would like something like this:
#include "GlobalEngineNeeded.h"
EngineNeeded *instanceOfThisEngine = new EngineNeeded();
Then, In each Engine that I would need another engine, I would do something like this (using graphics engine as example):
#include "GlobalParticleEngine.h"
#include "GlobalLightingEngine.h"
class GraphicsEngine
{ //instanceOfParticleEngine and instanceOfLightingEngine are used somewhere in here
.
.
.
};
Now here's the problem...All of this compiles (no compiler or linker error), but as SOON as I run my program, I get a runtime error (win32 programs are TERRIBLE at giving tips about runtime errors). I KNOW that it has to do with the way that I'm using these global variables. The reason I know this is b/c the runtime error comes even before my window is created, meaning it would have something to do with my .h files(please just take my word for it). Am I doing something wrong here? If there is a simple reason as to why this error is occurring, please let me know. Otherwise (and ONLY if you don't know how to fix my code), could someone advise me as to what they would do?