write a short note on Overloading of Binary Operator?
Answers were Sorted based on User's Feedback
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 |
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 |
Why is there no multiple inheritance?
can you explain how to use JavaBean in Project
What is the differances between a abstract calss and interface
what are the ways in which a constructors can be called?
What is the correct syntax for inheritance? 1) class aclass : public superclass 2) class aclass inherit superclass 3) class aclass <-superclass
Why do we use polymorphism?
Which keyword is written to use a variable declared in one class in the other class?
What is encapsulation oop?
How Do you Code Composition and Aggregation in C++ ?
What is polymorphism in oops with example?
i=20;k=0; for(j=1;k-i;k+=j<10?4:3) { cout<<k; } //please comment on the output
what is a ststic variable and stiticfunction briefly explain with exmple and in which case we use