I get a No viable overloaded '=' error with several candidates. Here are the details of the one I believe to be most relevant:
Candidate function not viable: no known conversion from
'__bind<void (Game::*)(cocos2d::Touch *, cocos2d::Event *), Game *>'
'std::__1::function<void (cocos2d::Touch *, cocos2d::Event *)>'
for 1st argument`
I've tried several different bind() arrangements but I'm not sure what the error is telling me. The types all seem to be correct in terms of the parameters and return value so I'm not sure why it won't accept it?
bind must be told what to do with parameters passed to its return value. By default, it simply discards them.
When you pass it to the std::function, it tries to type-erase it. std::function passes a Touch*, Event* to the bind. bind's return value discards them, and calls (this->*&Game::onTouchEnded)(), as you requested. This is not a valid call, and you get an error.
The simple way to fix this is to add placeholders that say "what do do with arguments to the bind return value". bind treats member functions as functions that take an extra this argument first. You want:
which corresponds to:
std::bind(&Game::onTouchEnded, this, _1, _2)
Now this is all well and good, but really you should avoid std::bind. Fully understanding it is tricky: It has strange corner cases that can bite you, or force you to needlessly type-erase, when you call it recursively.