Precautions With Function Overloading
Function overloading is a powerful feature of C++. But, this facility should not be overused. Otherwise it becomes an additional overhead in terms of readability and maintenance. Following precautions must be taken:
- Only those functions that basically do the same task, on different sets of data, should be overloaded. The overloading of function with identical name but for different purposes should be avoided.
- In function overloading, more than one function has to be actually defined and each of these occupy memory.
- Instead of function overloading, using default arguments may make more sense and fewer overheads.
- Declare function prototypes before main() and pass variables instead of passing constant directly. This will avoid ambiguity that frequently occurs while overloading functions.