Is there a way to overload the pointer assignment operator? e.g. overload pointer assignment operator for class A when
A *x, *y;
x = y;
See Question&Answers more detail:osIs there a way to overload the pointer assignment operator? e.g. overload pointer assignment operator for class A when
A *x, *y;
x = y;
See Question&Answers more detail:osNo, this is not possible. Pointer types are scalar types, but overloading operators requires a non-scalar parameter. In particular ([over.oper]p6):
An operator function shall either be a non-static member function or be a non-member function that has at least one parameter whose type is a class, a reference to a class, an enumeration, or a reference to an enumeration.
If you had a binary operator where one parameter was a user-defined type and the other a pointer, that would work, but in the situation you're asking about, both operands are pointers.