what is a binary overloading

Answer Posted / badmoon

Overloading binary operators (C++ only)

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 ?    4 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the fundamental idea of oop?

629


Is react oop?

606


What is polymorphism and example?

586


What is inheritance in simple words?

618


How oops is better than procedural?

581






Can an interface inherit a class?

552


Advantage and disadvantage of routing in telecom sector

780


How do you define a class in oop?

620


How do you explain polymorphism?

581


Write a program to reverse a string using recursive function?

1785


what are the realtime excercises in C++?

2329


What is the purpose of polymorphism?

668


What is destructor give example?

595


What is encapsulation process?

573


Describe these concepts: Polymorphism, Inheritance and Abstraction.

604