Preprocessor Conditionals

Posted by Mike on Stack Overflow See other posts from Stack Overflow or by Mike
Published on 2013-11-08T15:51:35Z Indexed on 2013/11/08 15:53 UTC
Read the original article Hit count: 199

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about c++

Related posts about preprocessor