c++ - No viable overloaded '=' for assigning std::function callback as member function -
i'm trying hook member function std::function
callback. callback type is:
std::function<void(touch*, event*)>
my member function is:
void game::ontouchended(touch* touch, event* event)
when try assign callback using following:
listener->ontouchended = bind(&game::ontouchended, this);
i no viable overloaded '='
error several candidates. here details of 1 believe relevant:
candidate function not viable: no known conversion '__bind<void (game::*)(cocos2d::touch *, cocos2d::event *), game *>' 'std::__1::function<void (cocos2d::touch *, cocos2d::event *)>' 1st argument`
i've tried several different bind() arrangements i'm not sure error telling me. types seem correct in terms of parameters , return value i'm not sure why won't accept it?
try
listener->ontouchended = bind(&game::ontouchended, this, std::placeholders::_1, std::placeholders::_2);
or try lambda function
listener->ontouchended = [this](touch* touch, event* event){ this->ontouchended(touch, event); };
Comments
Post a Comment