Function overloading by return type?

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

    I think this is a GAP in modern C++ definition… why ?

    int func();
    double func();
    
    // example 1. → defined
    int i = func();
    
    // example 2. → defined
    double d = func();
    
    // example 3. → NOT defined. error
    void main() 
    {
        func();
    }
    

    Why can a C++ compiler can not throw an error in example "3" and accept the code in example "1+2" ??

提交回复
热议问题