oop - Why can't I overload a function by its return type? -


this question has answer here:

why can't function not overloaded return types, there should no language support such overloading. want know reason happening if allow, or why not allowing such function overloading return type.

int func(); bool func(); int main() {      int iret = func();      bool bret = func(); } 

always arise quetion in mind. hoping satisfied answer.

a function

double function fn1() {  int = 2; return a;  } 

in above e.g. implicitly converted double when returned.

int function fn1() {  double = 2; return a;  } 

in above e.g. implicitly converted int when returned.

a fn call fn int = fn1(); or double = fn1();.

in either case both definitions can cause ambiguity called. fact returned values stored in int or double doesn't make difference in determining fn called. function first resolved , executed , return value assigned.

if both didn't have return type call fn1(); making ambiguous, whether call fn1() return type int or double


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -