错误信息
error: no match for ‘operator=’ (operand types are ‘std::function<bool(cocos2d::PhysicsContact&)>’ and ‘std::_Bind_helper<false, bool (GameLayer::)(cocos2d::EventCustom, const cocos2d::PhysicsContact&), GameLayer* const, const std::_Placeholder<1>&, const std::_Placeholder<2>&>::type {aka std::_Bind<std::_Mem_fn<bool (GameLayer::)(cocos2d::EventCustom, const cocos2d::PhysicsContact&)>(GameLayer*, std::_Placeholder<1>, std::_Placeholder<2>)>}’)
contactListener->onContactBegin = CC_CALLBACK_2(GameLayer::onContactBegin, this);
相关语句
auto contactListener = EventListenerPhysicsContact::create();
contactListener->onContactBegin = CC_CALLBACK_2(GameLayer::onContactBegin, this);
this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(contactListener, this);
…
…
bool GameLayer::onContactBegin(EventCustom* event, PhysicsContact& contact) {
this->gameOver();
return true;
}
试过把 bool GameLayer::onContactBegin(EventCustom* event, PhysicsContact& contact) 写成 bool GameLayer::onContactBegin(PhysicsContact& contact) ,或者把 CC_CALLBACK_2 换成 CC_CALLBACK_1,还是会报类似的错误。