write a short note on Overloading of Binary Operator?

Answers were Sorted based on User's Feedback



write a short note on Overloading of Binary Operator?..

Answer / rupinder

You overload a binary unary operator with either a nonstatic
member function that has one parameter, or a nonmember
function that has two parameters. Suppose a binary operator
@ is called with the statement t @ u, where t is an object
of type T, and u is an object of type U. A nonstatic member
function that overloads this operator would have the
following form:

return_type operator@(T)

A nonmember function that overloads the same operator would
have the following form:

return_type operator@(T, U)

An overloaded binary operator may return any type.

The following example overloads the * operator:

struct X {

// member binary operator
void operator*(int) { }
};

// non-member binary operator
void operator*(X, float) { }

int main() {
X x;
int y = 10;
float z = 10;

x * y;
x * z;
}

The call x * y is interpreted as x.operator*(y). The call x
* z is interpreted as operator*(x, z).

Is This Answer Correct ?    9 Yes 4 No

write a short note on Overloading of Binary Operator?..

Answer / saranya

In overloading binary operators the object to the left of the operator is used to invoke the operator function while the operand to the right of the operator is always passed as an argument to the function.
eg) sum.x = x + real.x
here x is used to invoke the function +() and real.x is passed as argument to that function.

Is This Answer Correct ?    8 Yes 5 No

Post New Answer

More OOPS Interview Questions

What is class and object in oops?

0 Answers  


Which is the parameter that is added to every non-static member function when it is called?

3 Answers   Accenture,


write a C++ program for booking using constructor and destructor.

0 Answers   HAL,


What is the difference between C++ and java?

6 Answers   Atos Origin,


What is abstrac class?where is it use?

2 Answers  


How to hide the base class functionality in Inheritance?

0 Answers   Viscus Infotech,


Will I be able to get a picture in D drive to the c++ program? If so, help me out?

0 Answers  


What does <> mean pseudocode?

0 Answers  


Write on signed and unsigned integers and give three (3) examples each

1 Answers  


Write a program to reverse a string using recursive function?

0 Answers   TCS,


what is difference between objects and function

1 Answers  


The type of variable a pointer points to must be the part of pointer's definition so that:

1 Answers   Infosys,


Categories