Nonstatic member function

Hello
I have a problem with error message: ...must be a nonstatic member function
unlike any I have found on forums.

My code is following:

1
2
3
4
5
class A {
public:
friend unsigned& operator=(unsigned&,A&);

};


Afterwards follows the definition of the functions.

Error message says, that this operator= must be a nonstatic member function, which it cannot be because the left operand is not member of the class.
I need to use this for the hash table.
Interesting is, that if I wrote + instead of =, the error disappeares.

Thanks for advise.

It can't be a friend, it has to be a member of the class with one parameter.

http://www.cplusplus.com/articles/jsmith1/

-- edit: fyi, this is for the assignment operator, that's why the '+' will work, but the '=' won't
Last edited on
You can make 'A' assignable to unsigned:

1
2
3
4
class A {
public:
operator unsigned () const /*e.g.*/ { return 100; }
};
coder777: Thanks, that is what I was looking for.
Topic archived. No new replies allowed.