answersLogoWhite

0

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.

User Avatar

Wiki User

12y ago

Still curious? Ask our experts.

Chat with our AI personalities

TaigaTaiga
Every great hero faces trials, and you—yes, YOU—are no exception!
Chat with Taiga
ProfessorProfessor
I will give you the most educated answer.
Chat with Professor
JordanJordan
Looking for a career mentor? I've seen my fair share of shake-ups.
Chat with Jordan
More answers

obj1 = obj2;

Operator "=" can be overloaded either by the member function or by the friend operator function.

In case of the friend function, the obj1 and obj2 are should be from the different classes. If they are from the same class, the compilation error will occur. We can't use the "this" pointer in the friend function since it is not the member function of the class.

So,

If both objects are from the same class it is better to for operator function (operator=) as member function.

If the objects are from the different class, then the operator function as friend function is advisable.

User Avatar

Wiki User

11y ago
User Avatar

Because there's no way to designate the left-hand operand of an assignment via a friend function. The left-hand operand is a given when assignment is implemented as a member function.

User Avatar

Wiki User

12y ago
User Avatar

* Assignment operator : =

* Function call operator : ()

* Subscripting operator : []

* Class member access operator.

User Avatar

Wiki User

12y ago
User Avatar

Add your answer:

Earn +20 pts
Q: Why a friend function cannot be used to overload the assignment operator?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Is sizeof an operator or function why?

You cannot overload the sizeof() operator because that could introduce uncertainty in its evaluation. The sizeof() operator must always produce an accurate and logically predictable result, thus all user-intervention is completely forbidden.


How will you overload a template function?

The only reason to overload a template function is to provide an overload that differs in the number and type of arguments that cannot be addressed by the template function alone. You simply declare them as you would any other overload. The overloads may themselves be template functions, but there must be no ambiguity: every template function must generate an unique function signature. Remember that template functions generate overloads at compile time on an as-required basis.


What are the disadvantages of scope resolution operator?

it cannot be operator overloaded.


Operator original function in OOP C plus plus?

I'm not sure I fully understand the question. Operators and functions are not the same. However, many operators also have named alternatives implemented as functions, such that "add" is synonymous with the binary increment operator while "plus" is synonymous with the unary plus operator. However these are completely separate implementations that do the same thing such that the function implementation typically invokes the operator (with implicit inline expansion to factor away the unwanted function call). There is no way to determine the underlying function of an operator, nor the underlying operator of a function without having access to the implementation source code. Such implementation details cannot be accessed at compile time let alone runtime.


Why do you use of operator overloading in c?

Overloading, Overriding, Polymorphism, Information Hiding, Inheritance all these are CONCEPTS of C++ and Java. An Object Oriented Language and not of C language. Thats why Bjarne Stroustrup came up with C++ ...