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

后端 未结 5 2008
佛祖请我去吃肉
佛祖请我去吃肉 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 13:01

    Const and non-const methods with the same formal parameter list can appear side-by-side because the this pointer is treated as a hidden argument and would have a different type. This may be used to provide mutating and non-mutating accessors as in the code in your question.

    If the signatures are exactly the same, then no.

提交回复
热议问题