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

Author Topic: sf::NonCopyable  (Read 1330 times)

0 Members and 1 Guest are viewing this topic.

GrimSkull

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
sf::NonCopyable
« on: February 06, 2013, 11:42:08 am »
I'm trying to create one window in a static variable and using a static function to return this variable to other classes and put them in reference-variables. But I keep getting:
(error C2248: 'sf::NonCopyable::NonCopyable' : cannot access private member declared in class 'sf::NonCopyable'   ...\sfml-2.0-rc\include\sfml\window\window.hpp   476)
and:
(error C2248: 'sf::NonCopyable::NonCopyable' : cannot access private member declared in class 'sf::NonCopyable'    ...\sfml-2.0-rc\include\sfml\graphics\rendertarget.hpp   369)

Window.h
#include <SFML/Graphics.hpp>

class Window
{
public:
   Window();

   static sf::RenderWindow getWindow();

private:
   void loadWindow();
   static sf::RenderWindow mWindow;
};

Window.cpp
#include "Window.h"

sf::RenderWindow Window::mWindow;

Window::Window()
{
   loadWindow();
}

void Window::loadWindow()
{
   mWindow.create(sf::VideoMode(1280, 768), "Robot split");
}

sf::RenderWindow Window::getWindow()
{
   return mWindow;
}

In the class where I'm trying to call the function Window::getWindow() looks like this:

Game.h
sf::RenderWindow& mWindow;

Game.cpp
#include "Window.h"
Game::Game(): mWindow(Window::getWindow())

In my mind this should give the adress from the static variable in Window.cpp to a reference-variable in Game.cpp, and thus Game.cpp should be able to access the window I create in Window.cpp. Or am I totally off course?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sf::NonCopyable
« Reply #1 on: February 06, 2013, 11:51:16 am »
Your function must return by reference, not by copy.

static sf::RenderWindow& getWindow();
Laurent Gomila - SFML developer

GrimSkull

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: sf::NonCopyable
« Reply #2 on: February 06, 2013, 01:12:40 pm »
Thanks, missed that... =)

 

anything