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;
no, it is not valid, but in your example it is, because the last const
is actually part of the signature (the hidden Foo *this
first parameter is now const Foo *this
).
It is used to access in read-only (get const reference, the method is constant), or write (get non-const reference, the method is not constant)
it's still a good design choice to return the reference of the same entity (constant or non-constant) in both methods of course!