2016-10-13 7 views
-2

私のクラスは私のヘッダファイルで定義されている、と私は私の.cppファイルに:クラスの外部のメンバ関数でメンバ関数をどのように呼び出すのですか?

bool Card::foo(const std::string &trump) const {...} 

bool Card::bar(const std::string &trump) const { 
    bool oof = foo(const std::string &trump);  
} 

これが何らかの理由で機能していません。 XCodeがエラーを起こしています:Expected Expression。同じことは、私がしようとしたときに行く:

bool oof = Card::foo(const std::string &trump); 
bool oof = foo(const std::string &trump) const; 
+5

'bool oof = foo(trump);'あなたはそれをあまりにも複雑にしています。 –

+0

const std :: stringが含まれていないのはなぜですか? – Goldname

+1

なぜそうなるはずですか? –

答えて

0

型情報がこのよう言語doesntの仕事ためのfoo(constのはstd ::文字列の一部)を呼び出すときに許可/必要ありません。関数の宣言ではそれを必要としますが、呼び出し時には型を含めません。イゴールの例を見てください。

2

チェック

bool Card::foo(const std::string &trump) const {...} 

bool Card::bar(const std::string &trump) const { 
    bool oof = foo(trump); 
} 

以下の式のいずれか:

bool Card::bar(const std::string &trump) const 

はすでにそれを定義しているので、

bool oof = foo(const std::string &trump); 
bool oof = Card::foo(const std::string &trump); 
bool oof = foo(const std::string &trump) const; 

trumpを再定義します。

関連する問題