Results 1 to 3 of 3
In one of my interview i faced a different question on function overloading.
Code:
void call(int a, int b){ }
int call(int a, float b){ return 1;}
The above functions ...
- 10-27-2010 #1Just Joined!
- Join Date
- May 2009
- Posts
- 21
reg: C++ function overloading
In one of my interview i faced a different question on function overloading.
This will gives error.Code:void call(int a, int b){ } int call(int a, float b){ return 1;} The above functions will compile and works fine. But, void call(int a, int b){} int call(int a, int b){}
So, why compiler is not taking the return type into consideration for checking the function overloading.
Thanks in advance,
MadhuLast edited by MikeTbob; 01-15-2011 at 10:15 PM. Reason: Added Code Tags
- 10-27-2010 #2Linux Newbie
- Join Date
- Mar 2010
- Posts
- 121
Quite simply it's because the compiler can't reliably differentiate between function calls based solely on return-type. For example, with the above two function definitions, a call like this:
obviously wants the second function, as the first one doesn't supply a return value, but one like this:Code:int x = call(0, 1);
is ambiguous - you could be meaning to call either function for their side-effects alone.Code:call(0, 1);
- 01-15-2011 #3Just Joined!
- Join Date
- Jan 2011
- Posts
- 1
function overloading and template
this website contains complete source code and tutorial on function overloading and templates in C++:
bitsbyta dot blogspot dot com


Reply With Quote
