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

Author Topic: RenderWindow reference problems  (Read 2952 times)

0 Members and 1 Guest are viewing this topic.

red436

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
RenderWindow reference problems
« on: January 18, 2013, 07:29:48 am »
I am trying to pass a reference of the applications render window to my image handling class. As you can see
i'm using a const which should not make a copy. However I get this error from gcc.

In file included from /usr/include/SFML/Window.hpp:37:0,
                 from globals.h:28,
                 from ImageHandling.h:1,
                 from ImageHandling.cpp:1:
/usr/include/SFML/System/NonCopyable.hpp: In member function ‘sf::Window& sf::Window::operator=(const sf::Window&)’:
/usr/include/SFML/System/NonCopyable.hpp:64:18: error: ‘sf::NonCopyable& sf::NonCopyable::operator=(const sf::NonCopyable&)’ is private
/usr/include/SFML/Window/Window.hpp:55:16: error: within this context
In file included from /usr/include/SFML/Window.hpp:35:0,
                 from globals.h:28,
                 from ImageHandling.h:1,
                 from ImageHandling.cpp:1:
/usr/include/SFML/System/NonCopyable.hpp: In member function ‘sf::Input& sf::Input::operator=(const sf::Input&)’:
/usr/include/SFML/System/NonCopyable.hpp:64:18: error: ‘sf::NonCopyable& sf::NonCopyable::operator=(const sf::NonCopyable&)’ is private
/usr/include/SFML/Window/Input.hpp:44:16: error: within this context
In file included from /usr/include/SFML/Window.hpp:37:0,
                 from globals.h:28,
                 from ImageHandling.h:1,
                 from ImageHandling.cpp:1:
/usr/include/SFML/Window/Window.hpp: In member function ‘sf::Window& sf::Window::operator=(const sf::Window&)’:
/usr/include/SFML/Window/Window.hpp:55:16: note: synthesized method ‘sf::Input& sf::Input::operator=(const sf::Input&)’ first required here
In file included from /usr/include/SFML/Graphics.hpp:38:0,
                 from globals.h:29,
                 from ImageHandling.h:1,
                 from ImageHandling.cpp:1:
/usr/include/SFML/Graphics/RenderWindow.hpp: In member function ‘sf::RenderWindow& sf::RenderWindow::operator=(const sf::RenderWindow&)’:
/usr/include/SFML/Graphics/RenderWindow.hpp:46:16: note: synthesized method ‘sf::Window& sf::Window::operator=(const sf::Window&)’ first required here
ImageHandling.cpp: In member function ‘void imageHandler::setScreen(const sf::RenderWindow&)’:
ImageHandling.cpp:15:16: note: synthesized method ‘sf::RenderWindow& sf::RenderWindow::operator=(const sf::RenderWindow&)’ first required here
make: *** [ImageHandling.o] Error 1

My code is as follows.

RenderWindow screen;

void imageHandler::setScreen(RenderWindow& screens) {
      screen = screens;
}
void imageHandler::surfApp( int x, int y, string imageName )
{
   map<string, Sprite>::iterator p = spriteList.find( imageName );
   if( p != spriteList.end() )
   {
       p -> second.SetPosition( x, y );
       screen.Draw( p -> second );
   }
}
 

 
« Last Edit: January 18, 2013, 09:14:56 am by Laurent »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: RenderWindow reference problems
« Reply #1 on: January 18, 2013, 08:40:52 am »
Next time, please provide a minimal and complete example, and use [code=cpp] tags.

Here, you create a copy:
screen = screens;
Even if screen is a reference, you try to assign an object. References cannot be re-bound after initialization, they have to be initialized in the constructor initializer list.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: