分类: C/C++
2011-03-30 22:25:55
Function overloading is the practice of
declaring the same function with different signatures. The same function
name will be used with different number of parameters and parameters of
different type. But overloading of functions with different return types are
not allowed.
For
example in this C++ Tutorial let us assume an AddAndDisplay function with
different types of parameters.
//C++ Tutorial - Sample code for
function overloading |
Some
times when these overloaded functions are called, they might cause ambiguity
errors. This is because the compiler may not be able to decide what signature
function should be called.
If the
data is type cast properly, then these errors will be resolved easily.
Typically, function overloading is used wherever a different type of data is to
be dealt with. For example this can be used for a function which converts
farenheit to celsius and vice versa. One of the functions can deal with the
integer data, other can deal float for precision etc.,