Home > Software design >  error: no matching function for call to 'sf::RenderWindow::draw(<unresolved overloaded funct
error: no matching function for call to 'sf::RenderWindow::draw(<unresolved overloaded funct

Time:09-29

I tried to create a Button class and use it with SFML, unfortunately, it produces the error: no matching function for call to 'sf::RenderWindow::draw(<unresolved overloaded function type>)'| and a few more.

This is the code:

void onclic(){

                    cout << "Clicked";

                }

class Button{

public:

    string ButtonText;

    Color color;

    int sizee;

    int x;

    int y;

    RenderWindow winname;

    void func(){

        cout << "\n";

    }

    void Butt(string ButtonText, Color color, int sizee, int x, int y, function<void()> funcc, RenderWindow winname){

        Text tt;

        tt.setString(ButtonText);

        tt.setColor(color);

        tt.setPosition(x, y);

        tt.setCharacterSize(sizee);

        Event e;

        while (winname.pollEvent(e)) {

            switch (e.type) {
        case Event::MouseButtonPressed:

            funcc();

            }
        }

    }

};

int main() {

    sf::RenderWindow sfmlWin;

    sfmlWin.setTitle("Hello!");

    sf::Font font;
    if (!font.loadFromFile("Raleway-Regular.ttf")) {

                               while (sfmlWin.isOpen()) {

        sf::Event e;
        while (sfmlWin.pollEvent(e)) {

            switch (e.type) {
            case sf::Event::EventType::Closed:

                using namespace sf;

                Text t;

                t.setCharacterSize(20);

                t.setString("Something");

                sfmlWin.draw(t);

            }
        }

        sfmlWin.clear();
        sfmlWin.draw(t);
        sfmlWin.display();
    }

        return -1;
    }


    sf::Text message("Hello, World!", font);

    while (sfmlWin.isOpen()) {

        sf::Event e;
        while (sfmlWin.pollEvent(e)) {

            switch (e.type) {
            case sf::Event::EventType::Closed:

                using namespace sf;

                Text t;

                t.setString("Something");

                sfmlWin.draw(t);

                Button buttt;

                Color col(0,255,0);

                buttt.Butt("CLICK!", col, 20, 50, 50, onclic, sfmlWin);

                sfmlWin.draw(buttt.Butt);

            }
        }

        if (e.type == sf::Event::MouseButtonPressed)
{
    if (e.mouseButton.button == sf::Mouse::Left)
    {

        if(e.mouseButton.x >= 20 && e.mouseButton.y >= 20 && e.mouseButton.x <= 40 && e.mouseButton.y <= 40){

            cout << "Pressed.";

        }

    }
}

        sfmlWin.clear();
        sfmlWin.draw(message);
        sfmlWin.display();


    }


    return 0;
}

This was the first error in the Build log in Code::Blocks. error: use of deleted function 'sf::RenderWindow::RenderWindow(const sf::RenderWindow&)'.

The very next line was In file included from C:\...\SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit\SFML-2.5.1\include/SFML/Graphics.hpp:47, from E:\something.cpp:4: C:\Users\...\SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit\SFML-2.5.1\include/SFML/Graphics/RenderWindow.hpp:44:25: note: 'sf::RenderWindow::RenderWindow(const sf::RenderWindow&)' is implicitly deleted because the default definition would be ill-formed: class SFML_GRAPHICS_API RenderWindow : public Window, public RenderTarget ^~~~~~~~~~~~

Where did I go wrong? Any idea?

I'm new to C so please go easy on me.

Thanks in advance!

CodePudding user response:

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

This tells you that you are trying to copy a sf::RenderWindow but a sf::RenderWindow is not copyable.

In the shown code, this is the offending copy:

void Butt(string ButtonText, Color color, int sizee, int x, int y,
          function<void()> funcc, RenderWindow winname)
//                                ^^^^^^^^^^^^

Make that a reference instead:

void Butt(string ButtonText, Color color, int sizee, int x, int y,
          function<void()> funcc, RenderWindow& winname)
//                                            ^
  • Related