简体   繁体   English

错误:没有匹配的函数调用 &#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++

I tried to create a Button class and use it with SFML, unfortunately, I get the error:我尝试创建一个 Button 类并将其与 SFML 一起使用,不幸的是,我收到错误消息:

E:\...\something.cpp:154:40: error: no matching function for call to 'sf::RenderWindow::draw(<unresolved overloaded function type>)'
                 sfmlWin.draw(buttt.Butt);
                                        ^

This is the code:这是代码:

#include <iostream>
#include <functional>
#include <SFML/Graphics.hpp>
using namespace std;
using namespace sf;

void onclic(){cout << "Clicked";}

class Button{
public:
    string ButtonText;
    Color color;
    int sizee;
    int x;
    int y;
    RenderWindow winname;
    void func(){cout << "Something";}

    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;
    while (sfmlWin.isOpen()) {
        sf::Event e;
        while (sfmlWin.pollEvent(e)) {
            switch (e.type) {
            case sf::Event::EventType::Closed:

                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);
            }
        }
        sfmlWin.clear();
        sfmlWin.display();
    }
    return 0;
}

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

If a Button class cannot be achieved in this way, is there any other way to implement it?如果一个Button类不能通过这种方式实现,有没有其他的实现方式?

Your class Button must be derived from sf::Drawable and in there you override the draw method:您的Button类必须从sf::Drawable派生,并在其中覆盖 draw 方法:

class Button : public sf::Drawable
{
protected:
    void draw (RenderTarget& target, RenderStates states) const override
    {
        // your draw implementation, which is called Butt() I think
    }
}

Then you pass it in your main like this:然后你像这样在你的 main 中传递它:

Button button;
sfmlWin.draw(button);

暂无
暂无

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

相关问题 错误:没有匹配的函数调用 &#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++ 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