Does not compile, error: use of deleted function

3

I have a simple project in codeblocks (windows), I am using the SFML library, when trying to call a method that I created where I pass the window and any object, compile I get the following error:

  

error: use of deleted function 'sf :: Window :: Window (const sf :: Window &)'

I use the following includes:

#include <SFML/Graphics.hpp>
#include <iostream>

Function I created:

bool LimitaMovimento(sf::RenderWindow window,sf::Sprite img){
    if(img.getPosition().x >= window.getPosition().x){
        return false;
    }else{
        return true;
    }
}

Call her in method main :

if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
        if(LimitaMovimento(window,img)){
              img.move(-5,0);
        }
        cout << window.getPosition().x <<endl;
}

* obs the window object has been instantiated obviously, without the LimitaMovimento call, works perfectly

    
asked by anonymous 20.03.2017 / 22:39

1 answer

3

You need to pass the window by reference.

bool LimitaMovimento(sf::RenderWindow& window,sf::Sprite img){
    if(img.getPosition().x >= window.getPosition().x){
        return false;
    }else{
        return true;
    }
}
    
20.03.2017 / 22:49