I am working on a little project in C++ with SDL2. I am trying to create a global window which I can use in my other .cpp files, but I cant figure out how to make a global variable in SDL. And please don't write something like "Don't use global variables", because I have to use them, otherwise it won't work.
Asked
Active
Viewed 602 times
1
-
Global variable in SDL works same like in C++, do you know how to use global variable in C++? If no, look on this thread http://stackoverflow.com/questions/9702053/how-to-declare-a-global-variable-in-c – Yevgeniy Logachev Apr 21 '16 at 13:36
-
You can have an argument of `SDL_Window *&` in your different functions and pass it around. Create the window in `main` send it to the application loop and close it when `main` exits. – Matt Apr 21 '16 at 13:37
1 Answers
4
In every file you need it just declare it as extern SDL_Window* GWindow;
and use it; then in single .cpp file define it SDL_Window* GWindow = nullptr;

Teivaz
- 5,462
- 4
- 37
- 75