Error while overloading operator (must be a nonstatic member function)

You are missing class name:

This is global operator, = cannot be global:

S &operator=(const S &s)

You must define this as class function:

S & S::operator=(const S &s)
//  ^^^

I believe PiotrNycz has provided the reasonable answer. Here please pardon me to add one more word.

In c++, assignment operator overloading function couldn't be friend function. Using friend function for operator=, will cause the same compiler error "overloading = operator must be a nonstatic member function".