Thursday, September 15, 2011

Understanding C++ Operator Overloading and User Defined Class Objects

In understanding c++ operator overloading we begin by defining the Concept. In C++ operator overloading means ‘providing different functionality to an operator under a different environment. Majority of the C++ built-in operators are already overloaded. Like functions, operators take operands (arguments) and return a value. operator overloading can be done on many operators for them to act in a specific manner on the argument or arguments and return a value.

To have a better understanding of c++ operator oveloading, let us look at this example. The plus (+) operator is overloaded to add two integers, increment an integer by one and concatenate a string. Likewise a minus (-) operator is overloaded to subtract two integers, and decrement an integer by one. Like the + and –, C++ provides built-in overloaded definitions for most operators to perform various functionalities directly but only on built-in types. However, C++ provides abilities for a programmer to overload built-in operators to act on user-defined types in a user-defined manner. Read the details onunderstanding C++ Operator Overloading

No comments:

Post a Comment