错误:没有匹配的函数调用'sf::RenderWindow::draw(<未解析的重载函数类型>)'| C++ 中的 SFML

业余编码员

我尝试创建一个Button类并将其与 SFML 一起使用,不幸的是,它产生了以下错误:no matching function for call to 'sf::RenderWindow::draw(<unresolved overloaded function type>)'|等等。

这是代码:

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;
}

这是 Code::Blocks 中 Build 日志中的第一个错误。error: use of deleted function 'sf::RenderWindow::RenderWindow(const sf::RenderWindow&)'.

下一行是 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++ 的新手,所以请放轻松。

提前致谢!

泰德·林格莫

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

这告诉您您正在尝试复制 asf::RenderWindow但 asf::RenderWindow不可复制。

在显示的代码中,这是有问题的副本:

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

改为参考:

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

C ++和SFML,没有重载函数“ sf :: RenderWindow.draw()”的实例与参数列表匹配

std :: unique_ptr会干扰某些sf :: RenderWindow函数?

发生没有匹配的函数来调用C ++中的错误

C ++错误没有匹配的调用函数

类sf :: RenderWindow'没有名为'clear'的成员

C ++中的多线程处理时出现“没有匹配的函数调用”错误

(SFML,C ++)如何访问动态分配的sf :: VertexArray中的特定sf :: Vertex?

c ++:函数“没有匹配的函数可调用”错误

C ++中的QFileDialog:“没有匹配的调用函数”

C ++错误没有匹配函数调用静态模板方法

C ++ Lambda-错误:没有匹配的函数可调用

C ++结构错误“没有匹配的调用函数...”

C ++错误::没有匹配的函数来调用'function'

SFML / C ++对sf :: Sprite的闪烁命中效果

您如何返回sf :: RenderWindow?

使用 sfml 向量的模板函数重载解析

使sf :: Shape为参数类型SFML

没有匹配的函数调用std :: transform,未解析的重载函数类型

没有匹配的函数无法调用未解析的重载函数类型

构造函数中没有用于调用的匹配函数-C ++ 11

C ++中没有匹配的函数:将常量标记添加到调用函数

gcc中无法解析的重载函数类型

rcpp中没有匹配的调用函数

C ++:没有匹配的函数可调用''

C ++:没有匹配的函数来调用

C ++模板:没有匹配的调用函数

C++ - 没有匹配的函数调用

C ++中的错误压缩代码-SFML

将 SFML RenderWindow 传递给类