Function overloading by return type?

前端 未结 14 2480
终归单人心
终归单人心 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:21

    As already shown - ambiguous calls of a function that differs only by return type introduces ambiguity. Ambiguity induces defective code. Defective code must be avoided.

    The complexity driven by the attempt to ambiguity shows that this is not a good hack. Apart from an intellectual exercise - why not use procedures with reference parameters.

    procedure(reference string){};
    procedure(reference int){};
    string blah;
    procedure(blah)
    

提交回复
热议问题