简体   繁体   English

错误:没有匹配的函数调用 &#39;sf::RenderWindow::draw(<unresolved overloaded function type> )&#39;| C++ 中的 SFML

[英]Error: no matching function for call to 'sf::RenderWindow::draw(<unresolved overloaded function type>)'| SFML in C++

I tried to create a Button class and use it with SFML, unfortunately, it produces the error:我尝试创建一个Button类并将其与 SFML 一起使用,不幸的是,它产生了错误:

no matching function for call to 'sf::RenderWindow::draw()'|没有匹配的函数调用'sf::RenderWindow::draw()'|

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.这是 Code::Blocks 中 Build 日志中的第一个错误。

error: use of deleted function 'sf::RenderWindow::RenderWindow(const sf::RenderWindow&)'.错误:使用已删除的函数 '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 ^~~~~~~~~~~~在 C:...\\SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit\\SFML-2.5.1\\include/SFML/Graphics.hpp:47 包含的文件中,来自 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:注意:'sf::RenderWindow::RenderWindow(const sf::RenderWindow&)' 被隐式删除,因为默认定义格式错误:class SFML_GRAPHICS_API RenderWindow : public Window, public RenderTarget ^~~~~~ ~~~~~~

Where did I go wrong?我哪里做错了?

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.这告诉您您正在尝试复制sf::RenderWindowsf::RenderWindow不可复制。

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)
//                                            ^

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:没有匹配的函数调用 &#39;sf::RenderWindow::draw(<unresolved overloaded function type> )&#39; SFML C++ - Error: no matching function for call to 'sf::RenderWindow::draw(<unresolved overloaded function type>)' SFML C++ C++ 和 SFML,没有重载函数“sf::RenderWindow.draw()”的实例与参数列表匹配 - C++ and SFML, no instance of the overloaded function "sf::RenderWindow.draw()" matches the argument list C++ 多线程错误:没有匹配的 function 调用 'std::thread::thread(<unresolved overloaded function type></unresolved> - C++ Multithreading Error : no matching function for call to 'std::thread::thread(<unresolved overloaded function type> 没有匹配的函数无法调用未解析的重载函数类型 - no matching function for call unresolved overloaded function type “没有匹配的函数可以调用...未解析的重载函数类型” - “No matching function for call to… unresolved overloaded function type” 没有匹配的函数可调用未解析的重载函数类型 - No matching function for call to unresolved overloaded function type 错误:没有匹配的函数可以调用&#39;sort(...,…, <unresolved overloaded function type> )&#39; - error: no matching function for call to 'sort(…, …, <unresolved overloaded function type>)' C ++错误:无效类型&#39; <unresolved overloaded function type> [int]&#39; - C++ error: invalid types '<unresolved overloaded function type>[int]' C ++ <unresolved overloaded function type> - c++ <unresolved overloaded function type> 我在C ++中得到未解决的错误重载函数类型 - I get error unresolved overloaded function type in c++
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM