string_rep , . , compute_cache_value , , string_rep .
const Date d2; undefined, , d2 (, - ) const_cast<Date*> , cache_valid false cache .
P.S. . , -, const_cast. mutable. , mutable , , const.
class Date
{
mutable bool cache_valid;
mutable string cache;
void compute_cache_value() const;
public:
string string_rep() const;
};
string Date::string_rep() const
{
if (cache_valid == false) {
compute_cache_value();
cache_valid = true;
}
return cache;
}
... , compute_cache_value cache_valid, operator string() const { return string_rep(); } Date.
, mutable, , , , , d2, , const.