[英]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.