Why a friend function cannot be used to overload the assignment operator?

1 answer

Answer

1175986

2026-04-29 10:50

+ Follow

Assignment(=) operator is a special operator that will be provided by the constructor to the class when programmer has not provided(overloaded) as member of the class.(like copy constructor).

When programmer is overloading = operator using friend function, two = operations will exists:

1) compiler is providing = operator

2) programmer is providing(overloading) = operator by friend function.

Then simply ambiguity will be created and compiler will gives error. Its compilation error.

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.