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
How to call a non virtual function in the derived class by using base class pointer
Following are the class specifications: class {int a}; class {int b}; Using friend funtion,calculate the max of two objects and display it.
How does polymorphism work?
Why do we use polymorphism in oops?
What is encapsulation with real life example?
Give two or more real cenario of virtual function and vertual object
What are the advantages of polymorphism?
Why is encapsulation used?
What is encapsulation and abstraction? How are they implemented in C++?
What are classes oop?
What is coupling in oops?
What is and I oop mean?
Why do we need polymorphism in c#?
What polymorphism means?
How do you achieve polymorphism?