Overloading by return type

前端 未结 11 1847
我在风中等你
我在风中等你 2020-11-22 07:07

I read few questions here on SO about this topic which seems yet confusing to me. I\'ve just begun to learn C++ and I haven\'t studied templates yet or operator overloading

11条回答
  •  一整个雨季
    2020-11-22 07:39

    No, you can't overload by return type; only by parameter types, and const/volatile qualifiers.

    One alternative would be to "return" using a reference argument:

    void get(int, int&);
    void get(int, char&);
    

    although I would probably either use a template, or differently-named functions like your second example.

提交回复
热议问题