Pointers to other things: can they be const ?
hzeller opened this issue · comments
For instance,we have code like this:
expr* get_right_expr() const { return right_expr_; }
This will return a pointer that allows to modify state, yet we have the method marked const
, which indicates that this todes not modify the object ... we can do so however through the backdoor.
So we should make this return a const expr*
const expr* get_right_expr() const { return right_expr_; }
iff we need writable and non-writable versions, we should do so having the same signature twice with and without const; the compiler will pick the right one in use.
const expr* get_right_expr() const { return right_expr_; }
expr* get_right_expr() { return right_expr_; }