简体   繁体   English

您如何在类外部的成员函数中调用成员函数?

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

相关问题 您如何在类的成员函数中调用复制构造函数? - How do you call the copy constructor within a member function of a class? 如何区分类成员函数和数据成员的声明 - How do you distinguish the declaration of a class member function and data member How do I call a member function inside a non-member function in C++ with an object created outside the non-member function? - How do I call a member function inside a non-member function in C++ with an object created outside the non-member function? 你称之为成员函数的成员函数是什么?如何编写成员函数? - What do you call a member function that follows a member function and how do I write one? 让类成员函数在类外部调用一个函数 - Having a class member function call a function outside the class 如何从另一个函数调用属于类成员的函数? - How do I call a function that is member of a class, from another function? 如何为类成员函数调用函数指针 - How to call function pointer for class member function 您如何在模板 class 中专门化成员 function? - How do you specialize a member function inside a template class? 类外的成员函数定义 - Member function definition outside the class class 之外的成员 function 定义 - Member function definition outside of class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM