Do not compile, error: use of Deleted Function

Asked

Viewed 244 times

3

I have a simple project on codeblocks (windows), I’m using the library SFML, when trying to call a method I created where I pass the window and any object, in the act of compiling 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;
    }
}

Her call in the method main:

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

*Obs the object window has already been instantiated obviously, without the call of the LimitaMovimento, works perfectly

1 answer

3


You have 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;
    }
}
  • It worked perfectly, thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.