C++ member functions with same name and parameters, different return type

后端 未结 5 1926
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-18 12:28

is it valid if I define member functions with same name¶meters but different return types inside a class like this:

class Test {
public:
    int a;
          


        
5条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-18 12:51

    No.

    You cannot overload on return type.

    Why? The standard says so.

    And it actually makes sense - you can't determine what function to call in all situations.

提交回复
热议问题