Why cannot a non-member function be used for overloading the assignment operator?

前端 未结 9 2176
南笙
南笙 2020-11-27 18:51

The assignment operator can be overloaded using a member function but not a non-member friend function:

class Test
{
    int a;
public:
    Test         


        
9条回答
  •  北海茫月
    2020-11-27 19:31

    $13.5.3 - "An assignment operator shall be implemented by a non-static member function with exactly one parameter. Because a copy assignment operator operator= is implicitly declared for a class if not declared by the user (12.8), a base class assignment operator is always hidden by the copy assignment operator of the derived class."

提交回复
热议问题