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 does <> mean pseudocode?

0 Answers  


What is the Advantage of Interface over the Inheritance in OOPS?

4 Answers  


what is the difference between a package and a software?

3 Answers  


In the following declaration of main, "int main(int argc, char *argv[])", to what does argv[0] usually correspond? 1) The first argument passed into the program 2) The program name 3) You can't define main like that

6 Answers  


How to call a non virtual function in the derived class by using base class pointer

3 Answers   HCL,






what is oops

4 Answers   DELL,


how can we design a magic square in c++?or suggest me the basic idea of it.

3 Answers  


What is pure oop?

0 Answers  


what is an qt4 interface?

1 Answers   IBM,


Explain virtual inheritance?

0 Answers  


What is encapsulation selenium?

0 Answers  


INSTANCE FIELDS DECLARED private ARE ACCESSIBLE BY THE METHODS ONLY.CAN WE CHANGE THE private FIELD OF AN OBJECT IN A METHOD OF SOME OTHER OBJECT OF THE SAME CLASS?

0 Answers  


Categories