SFML Window scopes?

Hello, so I tried to write SFML programs with multiple files and when I use a window defined elsewhere it cannot find it. Is their some way of creating Global windows?
when I use a window defined elsewhere it cannot find it


What do you mean?
When I open a window in one file I get errors when using it in another file.
Like
1
2
	sf::Window Splash;
    Splash.create(sf::VideoMode(800, 600), "Splash!");


I can not do anything using Splash in other files...
That's hardly helpful.

How are you attempting to use it?
Main File:
1
2
    sf::Window Splash;
    Splash.create(sf::VideoMode(800, 600), "Splash!");

Other File:
 
Splash.close();

Thats all I'm trying to do.
Last edited on
Is that a "Local Window?" since its defined inside of a function? Could I define it as a external global?
It is local to the function it was defined in, however if were to make a global variable out of every variable we needed access to outside of the function it was defined in, we would be quickly overwhelmed with global variables. Consider, instead, passing it by reference to the code that needs it.
Hopefully this helps, you have to pass the window to the other (class?) file.

Example:
Main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
#include "a.h"

int main () {
   sf::Window Splash;
   Splash.create(sf::VideoMode(800,600), "Splash!");

   A a(Splash);

   a.Close_Splash();

   return 0;
}


Other file (a.h):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class A {
Public:
   A (sf::RenderWindow &window);

   Close_Splash();

Private:
   sf::RenderWindow &window;
};

A::A (sf::RenderWindow &window):
   Window(window)
{}

void A::Close_Splash() {
   Window.close();
}


This *should* work.
Last edited on
Thanks. I never though of just using classes and references.
Topic archived. No new replies allowed.