Function overloading concept drive in C++ it
is function having same name but have different number, order and type of
arguments. Mainly, it doesn't depend on return type of function. It will
explain with the help of example.
Void fun()
{ }
Int fun()
{ int i=10;
return i;
}
Void main()
{ fun(); }
It occur ambiguity error because compiler
will confuse that which function it will execute. That function which return
nothing will not sure that it is of VOID type function. Because function with
return type will not surely to return a number.
While function overloading compiler get number
of function with same name to recognize every function differently, the compiler
done NAME MANGLING of that functions itself. Name of functions depend upon type,
order and number if arguments.
For example -
Void fun( int i )
Void fun( float f )
Void fun(int i ,float f )
It will convert as-
?F@@YAXH@Z( int i)
?F@@YAXM@Z(float f)
?F@@YAXHM@Z(int i, float f)
The
first function contain int hence the mangled name contain H same as for float
it contain M. as that way name mangling is done by compiler.