Function overloading by return type?

前端 未结 14 2271
终归单人心
终归单人心 2020-11-22 03:55

Why don\'t more mainstream statically typed languages support function/method overloading by return type? I can\'t think of any that do. It seems no less useful or reasona

14条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 04:26

    In such a language, how would you resolve the following:

    f(g(x))
    

    if f had overloads void f(int) and void f(string) and g had overloads int g(int) and string g(int)? You would need some kind of disambiguator.

    I think the situations where you might need this would be better served by choosing a new name for the function.

提交回复
热议问题