Global Class

So I'm into a delicated situation. I use SFML and GLEW. And I wanted to separate my main into more scripts in different files. And my big problem is I don't know how to declare window class global? Because other functions can't call it....
I believe you can create a .h file, which links to a .cpp file containing your class, and then link the .h file to all your code files. I am not sure though, I am new to coding (5-6 months) and am not very familiar with multi-file projects.
A global class or a global object?
Class member function definitions are implicitly inline, so they can be placed in header files without any issue. Global instances, as global variables, need to be declared extern every place they're used and defined in only one TU.

Header file:
1
2
class MyClass { /* whatever */ };
extern MyClass global_instance;


Source file A:
1
2
3
# include "header_file.hpp"
MyClass my_object;
global_instance.whatever();


Source file B:
1
2
# include "header_file.hpp"
MyClass my_object{ initializer };
I use SFML and GLEW. And I wanted to separate my main into more scripts in different files. And my big problem is I don't know how to declare window class global? Because other functions can't call it....

You don't want a global instance of a window class (the sometimes academic concern about order of initialization and global objects is real with SFML.) You do want to pass a reference to the window object to functions that require it.
Topic archived. No new replies allowed.