SFML community forums
Help => Window => Topic started by: BnMcG on March 06, 2015, 11:04:42 am
-
Hi there,
I'm trying to declare my SFML window as a "class-wide" variable so that I can use it in all of the class' methods (forgive me if this isn't the correct way of doing things, I'm coming from Java!)
I tried adding it as a private variable in my header like so:
private:
sf::Window windowMenu;
However my program then throws various errors about how Window is non-copyable? Is there any way to declare a window such that its scope is class-wide?
-
You have to make sure that the class which contains the sf::Window does not get copied too (e.g. define your own copy constructor for the class (or delete it/make it private))
btw: a better thread name would be "Declaring SFML Window as a member in a class" or something like that.
AlexAUT
-
You have to make sure that the class which contains the sf::Window does not get copied too (e.g. define your own copy constructor for the class (or delete it/make it private))
btw: a better thread name would be "Declaring SFML Window as a member in a class" or something like that.
AlexAUT
Thanks! I'll give this a go and report back. I've also updated the title, too.
-
Your exact problem is that you are copying your class instances somewhere. Either you pass them by value to another function/method or you are assigning it directly to another variable. What you most likely want to use are references. These must be declared explicitly in C++ whereas in Java they are implicitly everywhere (for class types).