write a short note on Overloading of Binary Operator?
Answer Posted / 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 |
Post New Answer View All Answers
What are the 3 pillars of oop?
What is oops concept with example?
How do you define a class in oop?
What is the real life example of polymorphism?
Why do we use oops?
Why is static class not inherited?
What is pointer in oop?
Is enum a class?
What is interface? When and where is it used?
What is encapsulation oop?
Are polymorphisms mutations?
What is a null tree?
Is this job good for future? can do this job post grduate student?
What are different types of JVM's? for example we use dalvik jvm for android then what about the remaining operating systems?
What is the difference between procedural programming and oops?