Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Declaring SFML Window as a member in a class  (Read 2597 times)

0 Members and 1 Guest are viewing this topic.

BnMcG

  • Newbie
  • *
  • Posts: 2
    • View Profile
Declaring SFML Window as a member in a class
« 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:

Quote
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?
« Last Edit: March 06, 2015, 06:41:42 pm by BnMcG »

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: Declaring SFML Window in header?
« Reply #1 on: March 06, 2015, 11:10:24 am »
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

BnMcG

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Declaring SFML Window as a member in a class
« Reply #2 on: March 06, 2015, 06:42:07 pm »
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.

BlueCobold

  • Full Member
  • ***
  • Posts: 105
    • View Profile
Re: Declaring SFML Window as a member in a class
« Reply #3 on: March 23, 2015, 06:33:03 am »
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).

 

anything