SFML community forums

Help => Graphics => Topic started by: learner on September 19, 2012, 11:57:47 am

Title: NonCopyable error when passing sf::RenderWindow to a function
Post by: learner on September 19, 2012, 11:57:47 am
I'm getting the following error when trying to pass sf::RenderWindow to a function.
I've gone throw few of the thread, but haven't been able to fix it yet.
Here are the errors :

/usr/local/include/SFML/System/NonCopyable.hpp:67: error: 'sf::NonCopyable::NonCopyable(const sf::NonCopyable&)' is private

and here's my source:

#include <SFML/Graphics.hpp>

void myFunc(sf::RenderWindow &window, sf::Vector2f size)
{
  sf::RectangleShape rect;
  rect.setSize(size);
  rect.setPosition(20.f,20.f);
  window.draw(rect,sf::RenderStates::Default);
}

int main()
{
  sf::RenderWindow win= sf::RenderWindow(sf::VideoMode(320,480,32),"My win");

  myFunc(win,sf::Vector2f(40,40));

  while(win.isOpen())
    {
      sf::Event event;
      while(win.pollEvent(event))
        {
          if(event.type==sf::Event::KeyPressed)
            win.close();
        }
     // win.clear();
      win.display();

    }

  return EXIT_SUCCESS;
}

Please do point out where I'm doing wrong.
Thanks.
Title: Re: NonCopyable error when passing sf::RenderWindow to a function
Post by: Laurent on September 19, 2012, 12:02:23 pm
The problem is not your function, which correctly takes a reference to the window, but here:
sf::RenderWindow win= sf::RenderWindow(sf::VideoMode(320,480,32),"My win");
You're creating a temporary RenderWindow and assigning it to the "win" variable by copy.

Do this instead:
sf::RenderWindow win(sf::VideoMode(320,480,32),"My win");
Title: Re: NonCopyable error when passing sf::RenderWindow to a function
Post by: learner on September 19, 2012, 12:08:28 pm
Thank you!
That worked out!