std::bind help

The GUI library uses std::bind in the button but It wont work because the function has arguments, I've been looking up stuff on it but i cant seem to figure it out what do I do?

Function:

void CreateWindow(string title, int width, int height);

GetSignal

button->GetSignal(sfg::Widget::OnLeftClick).Connect(std::bind(&App::CreateWindow, this));


Full code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <SFGUI/SFGUI.hpp>
#include <SFML/Graphics.hpp>
 
#include <iostream>
#include <string>
 
using namespace std;
 
class App
{
    public:
        void Program();
        void CreateWindow(string &title, int &width, int &height);
 
    private:
        sfg::Desktop dtop;
        sfg::SFGUI sfgui;
        sfg::Window::Ptr sfgui_window;
        sfg::Button::Ptr button;
};
 
void App::CreateWindow(string &title, int &width, int &height)
{
    sfgui_window = sfg::Window::Create();
 
    auto box_HOR = sfg::Box::Create(sfg::Box::Orientation::HORIZONTAL);
 
    auto box_VER = sfg::Box::Create(sfg::Box::Orientation::VERTICAL);
 
    sfgui_window->Add(box_VER);
 
    dtop.Add(sfgui_window);
}
 
void App::Program()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "App");
 
    window.resetGLStates();
 
    button = sfg::Button::Create("Create Window");
 
    button->GetSignal(sfg::Widget::OnLeftClick).Connect(std::bind(&App::CreateWindow, this));
 
    while(window.isOpen())
    {
        sf::Event event;
        while(window.pollEvent(event))
        {
            dtop.HandleEvent(event);
            switch(event.type)
            {
                case sf::Event::Closed:
                    window.close();
                break;
 
                default:
                    cout << "Error" << endl;
            }
        }
        dtop.Update(0.f);
        window.clear();
        sfgui.Display(window);
 
 
        window.display();
    }
}
 
int main()
{
    App app;
    app.Program();
 
    return 0;
}



||=== Build: Debug in vgsdfvsd (compiler: GNU GCC Compiler) ===|
C:\Users\thund_000\Desktop\vgsdfvsd\main.cpp||In member function 'void App::Program()':|
C:\Users\thund_000\Desktop\vgsdfvsd\main.cpp|43|error: no matching function for call to 'sfg::Signal::Connect(std::_Bind_helper<false, void (App::*)(std::basic_string<char>&, int&, int&), App* const>::type)'|
C:\Users\thund_000\Desktop\vgsdfvsd\main.cpp|43|note: candidate is:|
C:\SFGUI\include\SFGUI\Signal.hpp|40|note: unsigned int sfg::Signal::Connect(std::function<void()>)|
C:\SFGUI\include\SFGUI\Signal.hpp|40|note: no known conversion for argument 1 from 'std::_Bind_helper<false, void (App::*)(std::basic_string<char>&, int&, int&), App* const>::type {aka std::_Bind<std::_Mem_fn<void (App::*)(std::basic_string<char>&, int&, int&)>(App*)>}' to 'std::function<void()>'|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
Last edited on
Topic archived. No new replies allowed.