简体   繁体   中英

Some questions about functions with a class type

So I am using C++ and experimenting with classes. I am trying to create a function with a class type. Here is the code:

struct action{
void setup(std::string){
/*...*/
}
};
action move(){
setup("*");//<-error:[use of undeclared identifier 'setup']
}

Can the instance function of the class access its member functions and objects? Also, what should it return? Do i have to create a seperate action instance to return? Can it be related to the action move ?Thanks!

For starters the function setup is a non-static member function of the class action . It can be used applied to an object of the class. And the function move returns nothing though it has the return type action .

The function move can look like

action move()
{
    action a;

    a.setup("*");

    return a;
}

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