Class c;
T& t = c.get_data() // Not allowed.
const T& tc = c.get_data() // OK.
const T& get_data() const { return data_; }
^^^^^
意味着该方法不会修改类的任何成员变量(除非该成员是 mutable)。
void Class::get_data() const {
this->data_ = ...; // is not allowed here since get_data() is const (unless 'data_' is mutable)
this->anything = ... // Not allowed unless the thing is 'mutable'
}