SFML Window scopes?

Pickle Gunner (63)
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?
cire (1851)
when I use a window defined elsewhere it cannot find it


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


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

How are you attempting to use it?
Pickle Gunner (63)
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
Pickle Gunner (63)
Is that a "Local Window?" since its defined inside of a function? Could I define it as a external global?
cire (1851)
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.
jgeorge (14)
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
Pickle Gunner (63)
Thanks. I never though of just using classes and references.
Registered users can post here. Sign in or register to post.