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
i am getting an of the type can not convert int to int *. to overcome this problem what we should do?
What is an example of genetic polymorphism?
What is coupling in oop?
What is oops and its features?
What is the difference between inheritance and polymorphism?
What is object in oops?
write a program using c++ to implement single contiguous memory mangement techniques.display the content of the main memory after yhe allocation of jobs and percentage of the wastage of the main memory
Why is destructor used?
Is data hiding and abstraction same?
write string class as your own class in java without using any built-in function
Why oops is important?
What is constructor in oop?
What are classes oop?
What exactly is polymorphism?
What is object and example?