I have a Button
class, and I'm trying to add a callback function to it. Following the accepted answer to this question, here's the layout of my classes:
class Button {
public:
void SetCallbackFunc(std::function<void()> const& f) {
callbackFunc = f;
}
private:
std::function<void()> callbackFunc;
};
class SomeOtherClass {
public:
void DoThings();
void SetupButtonFunctionality() {
Button *b = new Button();
b->SetCallbackFunc(std::bind(&SomeOtherClass::DoThings, this, std::placeholders::_1));
}
};
And these are all the compilation errors I'm getting:
error C2977: 'std::add_reference' : too many template arguments
error C2955: 'std::add_reference' : use of class template requires template argument list
error C2146: syntax error : missing ',' before identifier 'type' (Content\SomeOtherClass.cpp)
error C2065: 'type' : undeclared identifier (Content\SomeOtherClass.cpp)
error C2064: term does not evaluate to a function taking 2 arguments (Content\SomeOtherClass.cpp)
error C2064: term does not evaluate to a function taking 0 arguments (GUI\Button.cpp)
error C2027: use of undefined type 'std::tuple_element<0,_Ftuple>'
What's wrong with the code? Is there another simple way to write what I want?