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

前端 未结 2 1013
野性不改
野性不改 2020-12-29 05:48

I\'m writing string class on my own. And I have such code. I just want to overload operator=. This is my actual code, and I get error in last part of code.

2条回答
  •  时光取名叫无心
    2020-12-29 06:15

    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)
    //  ^^^
    

提交回复
热议问题