没有匹配“运算符”>>'在“本地”中

发布于 2024-11-19 01:59:00 字数 1285 浏览 2 评论 0原文

此函数阻止 Wagic:自制程序编译:

/home/white/Pandora/wagic-read-only/projects/mtg/src/GameOptions.cpp:1156: error: 与“operator>>”不匹配在 的 >>本地'

源(GameOptions.cpp):http:// /code.google.com/p/wagic/source/browse/trunk/projects/mtg/src/ GameOptions.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;
}

我将如何重写它以使其能够编译?

This function is preventing Wagic: the homebrew from Compiling:

/home/white/Pandora/wagic-read-only/projects/mtg/src/GameOptions.cpp:1156: error: no match for ‘operator>>’ in ‘s >> local’

Source(GameOptions.cpp): http://code.google.com/p/wagic/source/browse/trunk/projects/mtg/src/ GameOptions.cpp
Source(General):
http://code.google.com/p/wagic/source/browse/

(Line 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;
}

How would I rewrite this to get it to compile?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

断肠人 2024-11-26 01:59:01
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;
}
s >> local

Calls the default operator >> which does not understand your custom class LocalKeySym So You need to Overload the Operator >> for your custom class LocalKeySym.

An sample code:

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;
}
纵性 2024-11-26 01:59:01

operator >> 仅针对内置类型定义,如 intfloatchar、< code>double 等,可以使用指针输入地址。由于您的变量 local 是自定义类型 LocalKeySym。您可能必须定义自己的运算符>>

它应该类似于重载 istream 和 ostream 运算符。请参阅教程

operator >> is defined only for built-in types like, int, float, char, double etc. and it can input the address using pointers. Since your variable local is of custom type LocalKeySym. you may have to define your own operator >>.

It should be similar to overloading istream and ostream operators. See the tutorial here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文