简体   繁体   中英

c++ syntax of define member function that take in int and return pointer to in at outside of the class

i have a problem in my c++ lab assignment ,i been searching google and i tried with this syntax and it won't show unqualified-Id compile error

typedef int (list::*find)(int val);
{
    return 0;
}

在此处输入图片说明 在此处输入图片说明 The declaration at header file

class list {
public:
int *find(int val);
}

what is the syntax of define a member function that take in int and return pointer to in at outside of the class?

This would be the correct syntax:

int* list::find(int val)
{
    // Implementation
}

The function declaration isn't that of a function pointer, which is what it seems you are trying to do, but a function that returns a pointer to an integer.

The general syntax of a member function defined outside a class is:

ReturnType Class::FunctionName([OptionalParameters]) [OptionalQualifiers]
{
    // Implementation
}

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