answersLogoWhite

0


Best Answer

Operator overloading allows you to redefine the functionality of most of the operators, such as + and -. This allows you to create a class that can naturally mimic a native object, such as an integer. Consider a complex number class. Clearly, you would want to overload the basic mathematical operations add, subtract, multiply, and divide, so that a user of your class code could write expressions involving complex numbers without having to think about the implementation details of your class. In the case of other types of classes, for instance a stack class, the meaning of the operators needs to be carefully considered, but it might make sense, for instance, to write a stack push operation as a unary plus, and a pop operation as a unary minus. Certainly, you don't want to go crazy overloading operators just because you can - you want the resulting code to be sensible and readable.

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are the advantages of operator overoloading in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the operator that cannot be overloaded in c plus plus and java?

conditional operator , size of operator , membership operator and scope resulation operator can not be overload in c++


What is the operator is used to allocate the memory in c plus plus?

calloc operator,malloc operator


What is the operator of power in c plus plus?

There is no "power" operator in C or C++. You need to the use the math library function pow().


Example of binaray operator in c plus plus?

+ is an example, one of many, of a binary operator in C or C++ a = b + c; // for usage example


What is the memory management operator in c plus plus?

There is no memory management operator in C++ -- it is an unmanaged language. You use the C++ new operator to allocate memory, and use the C++ delete operator to release previously allocated memory.


Why are there 2 plus sign in c plus plus and Why not a single plus sign?

In C and in C++, the ++ operator means to increment. C++ was intended to be the next version, i.e. the incremental next step, of C, hence the use of the ++ operator.


What do the two plus stand for in C plus plus?

The ++ in C++ refers to the postfix increment operator (operator++()). It's literal meaning is "the successor to C", in reference to the C language upon which the C++ language is based.


Can the scope resolution operator be overloaded in C plus plus?

No.


How unary minus can be overload in c plus plus?

type operator- ();


Which operator is used for deallocating memory in c plus plus?

delete


Which operator cannot be overloaded c plus plus?

comma (,) is an example


What are special operators in c plus plus?

The only "special" operators in C++ are those that cannot be overloaded. That is; the dot member operator (.), pointer to member operator (.*), ternary conditional operator (:?), scope resolution operator (::), sizeof() and typeof().