2011-07-10 3 views
0

この関数はWagicを妨げている:コンパイルから自作:ませマッチ>>ローカル」

/ホーム/白/パンドラ/ wagic-読み取り専用/プロジェクト/ MTGを/ SRC/GameOptions.cpp:1156:エラー:不一致のための '演算子>>' 内の>>ローカル」

ソース(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; 
} 

これをコンパイルするにはどうすればいいですか?

答えて

2
s >> local 

は、カスタムクラスLocalKeySymを理解するので、あなたはあなたのカスタムクラスLocalKeySymためOperator >>をオーバーロードする必要はありませんデフォルトoperator >>を呼び出します。

サンプルコード:

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

operator >>のみ内蔵int、等の種類、floatchardouble等のために定義され、それは入力ポインタを使用してアドレスすることができます。変数localはカスタムタイプLocalKeySymです。あなた自身がoperator >>を定義しなければならないかもしれません。

istreamオペレータとostreamオペレータのオーバーロードに似ているはずです。 tutorial hereを参照してください。

関連する問題