c++ - 在 'Operator>>' 中没有匹配 's>>local"

标签 c++ compiler-errors operator-keyword

此函数阻止 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/

相关文章:

c++ - 通过进程或 dll 的内存转储识别内存代码注入(inject)

c++ - 关于 C++ 中 double 和 int 之间转换的奇怪结果

c++ - 按照第一个 hello world 示例在 VS2010 中获取编译错误

java - FileNotFoundException未报告

c++ - 在已经定义运算符C++时不匹配

c++ - Visual Studio 2017 创建/调试程序

c++ - sizeof(Structure) 困惑

compiler-errors - 不稳定的混音编译器错误 “Unknown exception during compilation”

c++ - 全局操作符 + 覆盖冲突检测

c++ - 读取使用运算符创建的矩阵