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

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

    Why friend function can't be used for overloading assignment operator?

    Short answer: Just because.

    Somewhat longer answer: That's the way the syntax was fixed. A few operators have to be member functions. The assignment operator is one of the,

提交回复
热议问题