我想做一个OIS :: Keys(int)和std :: function数组。
我有这个 :
struct UserCommands
{
OIS::KeyCode key;
std::function<bool(Worms *, const Ogre::FrameEvent& evt)> func;
};
UserInput input;
UserCommands usrCommands[] =
{
{
OIS::KC_A, std::bind(&input, &UserInput::selectBazooka)
},
};
但是当我尝试编译这个时,我有这个编译错误:
In file included from includes/WormsApp.hh:5:0,
/src/main.cpp:2:
/includes/InputListener.hh:26:25: error: could not convert ‘std::bind(_Func&&, _BoundArgs&& ...) [with _Func = UserInput*; _BoundArgs = {bool (UserInput::*)(Worms*, const Ogre::FrameEvent&)}; typename std::_Bind_helper<std::__is_socketlike<_Func>::value, _Func, _BoundArgs ...>::type = std::_Bind<UserInput*(bool (UserInput::*)(Worms*, const Ogre::FrameEvent&))>](&UserInput::selectBazooka)’ from ‘std::_Bind_helper<false, UserInput*, bool (UserInput::*)(Worms*, const Ogre::FrameEvent&)>::type {aka std::_Bind<UserInput*(bool (UserInput::*)(Worms*, const Ogre::FrameEvent&))>}’ to ‘std::function<bool(Worms*, const Ogre::FrameEvent&)>’
OIS::KC_A, std::bind(&input, &UserInput::selectBazooka)
^
我做错了什么?
的第一个参数std::bind
是可调用对象。就您而言,应为&UserInput::selectBazooka
。之后,与对该成员函数(&input
)的调用相关联的对象将消失(您颠倒了此顺序)。尽管如此,您仍必须对缺少的参数使用占位符:
std::bind(&UserInput::selectBazooka, &input, std::placeholders::_1, std::placeholders::_2)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句