just to clarify,
"it" - are you refering here to the definition of the "const member
function"?
> It is a side effect of the fact that '*this' is constant *inside* that
> function. Every part of '*this' is considered constant *inside*
> 'foo'. When you try to return 'p_', it is constant, and the compiler
> would have to convert a const lvalue to a non-const lvalue in order to
> bind the reference (the return value) to it. *That* is prohibited.
>
>
ok, so we can think that p_ (after declaring the function as const
function) becomes like:
const int p_;
And then for example for:
int foo() const { return p_; }
it would mean that we are doing a copy for the return value:
int return = p_;
which works because const can be copied to an int.
But with reference return value it would be like:
int& return = p_;
which is not working because non-const ref cannot refer to a const. Right?
If I see it like this then its easy to understand....