Why dont languages allow overloading of methods by return value? -


Ignore the return value in C, Java and many other languages.

  int i = func () float f = func () int func () {return 5} float func () {return 1.3}  

above Why is not legal? Does this make it more difficult for the program

  int i = func (func (func2 (func3 ())) // You do not know what you're getting  

Is it hard to write a compiler? Is there more language futility? Is there a language that can do the above?

What about this matter?

  Class A tool Fu {/*...*/} Implementation of class B Foo {/*...*/} A Funk () {New A (Return); } B. Funk () {New B (Return); } Fu Wei = Monk (); // Do you call?!  

When you allow overloading of a function name, there are problems before ambiguity, which argue differently. Along with checking back type, it is very difficult to solve the correct work.

I am sure a language can implement it, but it will make things more complicated, and generally the code is difficult to understand.


Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -