Beneifts and Examples of Overloading

Started by thiruvasagamani, Aug 08, 2008, 08:03 PM

Previous topic - Next topic

thiruvasagamani

Benefits of Overloading

By overloading standard operators on a class, you can exploit the intuition of the users of that class. This lets users program in the language of the problem domain rather than in the language of the machine.

The ultimate goal is to reduce both the learning curve and the defect rate.


Here are a few of the many examples of operator overloading:

myString + yourString might concatenate two std::string objects

myDate++ might increment a Date object

a * b might multiply two Number objects

a might access an element of an Array object

x = *p might dereference a "smart pointer" that "points" to a disk record — it could seek to the location on disk where p "points" and return the appropriate record into x
Thiruvasakamani Karnan