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

Author Topic: NonCopyable error when passing sf::RenderWindow to a function  (Read 1288 times)

0 Members and 1 Guest are viewing this topic.

learner

  • Newbie
  • *
  • Posts: 2
    • View Profile
NonCopyable error when passing sf::RenderWindow to a function
« 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: NonCopyable error when passing sf::RenderWindow to a function
« Reply #1 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");
Laurent Gomila - SFML developer

learner

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: NonCopyable error when passing sf::RenderWindow to a function
« Reply #2 on: September 19, 2012, 12:08:28 pm »
Thank you!
That worked out!