Why dont languages allow overloading of methods by return value?

前端 未结 8 522
[愿得一人]
[愿得一人] 2021-01-02 08:38

c, java and many other languages do not pay attention to return values.

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


        
8条回答
  •  被撕碎了的回忆
    2021-01-02 09:13

    For a C++ example, consider:

    void g(int x);
    void g(float x);
    g(func());
    

    Which of the overloaded g() functions would be called?

提交回复
热议问题