Search code examples
c++syntaxpointer-to-member

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;
}

enter image description here enter image description here 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?


Solution

  • 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
    }