A temporary has a type, that type can be const, and it can be non-const. You can call a non-const member function only on a non-const object. withOutConst()
yield a temporary of type My
, withConst()
yields a temporary of type const My
.
Maybe you have the misconception that a temporary is always const
? If that is the case, then it is wrong.