Preprocessor Conditionals
- by Mike
I was wondering if it would be possible to have a define which changes values at some point in the code be used in a conditional. Basically something like this:
//////////////////////////////////////////// SomeFile.cpp
#define SHUTDOWN false
while(window->isOpen())
{
if(SHUTDOWN)
window->close();
// Rest of the main loop
}
//////////////////////////////////////////// SomeOtherFile.cpp
if(Escape.isPressed())
{
#undef SHUTDOWN
#define SHUTDOWN true
}
Thus causing the app to close. If it's not, would having a function like
RenderWindow* getWindow()
{
return window;
}
and then calling
if(Escape.isPressed())
getWindow()->close();
The best way to do it? I'd rather not go that route because the classes that are calling the key event are members of the class controlling the main loop and the window, so I'd have to set pointers to the containing class in the smaller classes to call getWindow() and it just seems like a more complicated method. But if I can't do it with preprocessor directives I'll just have to use pointers to the parent class.