使用vs2013编写cocos2dx的代码:
_touchListener = EventListenerTouchOneByOne::create();
_touchListener->setSwallowTouches(true);
_touchListener->onTouchBegan = CC_CALLBACK_2(HelloWorld::onTouchBegan, this);
_touchListener->onTouchMoved = CC_CALLBACK_2(HelloWorld::onTouchesMoved, this);
_touchListener->onTouchEnded = CC_CALLBACK_2(HelloWorld::onTouchEnded, this);
_touchListener->onTouchCancelled = CC_CALLBACK_2(HelloWorld::onTouchCancelled, this);
结果编译时报如下错误
error C2664: “void std::_Pmf_wrap<void (__thiscall cocos2d::Layer::* )(const std::vector<cocos2d::Touch *,std::allocator<_Ty>> &,cocos2d::Event *),void,cocos2d::Layer,const std::vector<_Ty,std::allocator<_Ty>> &,cocos2d::Event *>::operator ()(_Farg0 &,const std::vector<_Ty,std::allocator<_Ty>> &,cocos2d::Event *) const”: 无法将参数 2 从“cocos2d::Touch *”转换为“const std::vector<cocos2d::Touch *,std::allocator<_Ty>> &” d:\program files (x86)\microsoft visual studio 12.0\vc\include\functional 1149 1 GameCenter
从错误的意思看是说不能将cocos2d::Touch *转换为const std::vector<cocos2d::Touch *,std::allocator<_Ty>> &
最终发现是因为写错了函数,_touchListener->onTouchMoved = CC_CALLBACK_2(HelloWorld::onTouchesMoved, this);
这里将HelloWorld::onTouchMoved错写成了HelloWorld::onTouchesMoved,导致函数不匹配。