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

前端 未结 9 2191
南笙
南笙 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:38

    Because there is already an implicit operator overloading function for '=' in the class to do shallow copying. So even if you overload using a a friend function you will never be able to call it as any call made by us would call the implicit shallow copying method rather than the overloaded friend function.

提交回复
热议问题