[英]How do you call a member function in a member function outside of a class?
My class is defined in my header file, and in my .cpp file I have: 我的班级定义在我的头文件中,而在我的.cpp文件中,我具有:
bool Card::foo(const std::string &trump) const {...}
bool Card::bar(const std::string &trump) const {
bool oof = foo(const std::string &trump);
}
This is not working for some reason. 由于某些原因,此方法不起作用。 XCode is giving an error: Expected Expression. XCode提供了一个错误:期望的表达式。 The same goes when I try: 当我尝试时也是如此:
bool oof = Card::foo(const std::string &trump);
bool oof = foo(const std::string &trump) const;
Check 校验
bool Card::foo(const std::string &trump) const {...}
bool Card::bar(const std::string &trump) const {
bool oof = foo(trump);
}
Any of the expression below: 以下任何表达式:
bool oof = foo(const std::string &trump);
bool oof = Card::foo(const std::string &trump);
bool oof = foo(const std::string &trump) const;
would redefine the trump
since 将重新定义trump
因为
bool Card::bar(const std::string &trump) const
has already defined it. 已经定义了它。
The type information is not required/allowed when calling foo (the const std::string part) because the language doesnt work this way. 调用foo(const std :: string部分)时,不需要/不允许类型信息,因为这种语言无法正常工作。 The function declaration will need it, but do not include the type when calling it. 函数声明将需要它,但是在调用它时不包括类型。 Look at Igor's example. 看伊戈尔的例子。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.