InterviewSolution
| 1. |
Write a C++ program in which you have to take two numbers from user and perform basicarithmetic operations. Using if-else statementsdecide, what operation user want to do so yourprogram must fulfill user's requirements.(Note: Static or Dynamic memory allocation) |
|
Answer» When an operator is OVERLOADED with multiple jobs it is known as operator overloading. It is a way to implement compile TIME polymorphism.Key Points about Operator OverloadingFor operator overloading to work, at least one of the operands must be a USER defined class object.Compiler automatically creates a default assignment operator with every class. The default assignment operator does assign all members of right side to the left side and works fine most of the cases (this behavior is same as copy constructor).We can also write conversion operators that can be used to convert one TYPE to another type.Any constructor that can be called with a single argument works as a conversion constructor, means it can also be used for implicit conversion to the class being constructed.1. Arithmetic Operator OverloadingFollowing is the EXAMPLE to demonstrate arithmetic operator overloading.Example |
|