簡體   English   中英

您如何在類外部的成員函數中調用成員函數?

[英]How do you call a member function in a member function outside of a class?

我的班級定義在我的頭文件中,而在我的.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提供了一個錯誤:期望的表達式。 當我嘗試時也是如此:

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

校驗

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

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

以下任何表達式:

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

將重新定義trump因為

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

已經定義了它。

調用foo(const std :: string部分)時,不需要/不允許類型信息,因為這種語言無法正常工作。 函數聲明將需要它,但是在調用它時不包括類型。 看伊戈爾的例子。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM