简体   繁体   中英

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:

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. 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

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. The function declaration will need it, but do not include the type when calling it. Look at Igor's example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM