开发者

No Match for 'Operator>>' in 's>>local"

This function is preventing Wagic: the homebrew from Compiling:

/home/white/Pandora/wagic-read-only/pro开发者_StackOverflowjects/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?


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜