Nov 1, 2012 at 7:01pm Nov 1, 2012 at 7:01pm UTC
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?
Nov 1, 2012 at 9:19pm Nov 1, 2012 at 9:19pm UTC
When I open a window in one file I get errors when using it in another file.
Nov 1, 2012 at 9:41pm Nov 1, 2012 at 9:41pm UTC
That's hardly helpful.
How are you attempting to use it?
Nov 1, 2012 at 9:46pm Nov 1, 2012 at 9:46pm UTC
Main File:
1 2
sf::Window Splash;
Splash.create(sf::VideoMode(800, 600), "Splash!" );
Other File:
Thats all I'm trying to do.
Last edited on Nov 1, 2012 at 9:46pm Nov 1, 2012 at 9:46pm UTC
Nov 1, 2012 at 10:04pm Nov 1, 2012 at 10:04pm UTC
Is that a "Local Window?" since its defined inside of a function? Could I define it as a external global?
Nov 2, 2012 at 12:46am Nov 2, 2012 at 12:46am UTC
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.
Nov 2, 2012 at 2:55am Nov 2, 2012 at 2:55am UTC
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 Nov 2, 2012 at 2:57am Nov 2, 2012 at 2:57am UTC
Nov 2, 2012 at 9:04pm Nov 2, 2012 at 9:04pm UTC
Thanks. I never though of just using classes and references.