此函数阻止 Wagic:自制程序编译:
/home/white/Pandora/wagic-read-only/projects/mtg/src/GameOptions.cpp:1156: 错误:'s >> local' 中的'operator>>'不匹配
来源(GameOptions.cpp):http://code.google.com/p/wagic/source/browse/trunk/projects/mtg/src/游戏选项.cpp 来源(一般): http://code.google.com/p/wagic/source/browse/
(第 1142-1172 行)
bool GameOptionKeyBindings::read(string input)
{
istringstream iss(input);
vector<pair<LocalKeySym, JButton> > assoc;
while (iss.good())
{
stringstream s;
iss.get(*(s.rdbuf()), ',');
iss.get();
LocalKeySym local;
char sep;
u32 button;
s >> local >> sep >> button;
if (':' != sep)
return false;
assoc.push_back(make_pair(local, u32_to_button(button)));
}
if (assoc.empty())
return false;
JGE* j = JGE::GetInstance();
j->ClearBindings();
for (vector<pair<LocalKeySym, JButton> >::const_iterator it = assoc.begin(); it != assoc.end(); ++it)
j->BindKey(it->first, it->second);
return true;
}
我该如何重写它才能编译?
最佳答案
s >> local
调用默认的 operator >>
它不理解你的自定义类 LocalKeySym
所以你需要为你的自定义重载 Operator >>
类 LocalKeySym
。
示例代码:
std::istream& operator>>(std::istream& is, LocalKeySym& obj)
{
// read LocalKeySym obj from stream
if( /* no valid object of LocalKeySym found in stream */ )
is.setstate(std::ios::failbit);
return is;
}
关于c++ - 在 'Operator>>' 中没有匹配 's>>local",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6639385/