#include <iostream> #include <string.h> using namespace std; struct cache { bool valid; string rep; cache(bool v, std::string s="") : valid(v), rep(s) { } }; class Date { cache* c; void computer_cache_value() const { cout << "void computer_cache_value() const" << '/n'; } public: Date() { c = new cache(false, "chain"); } ~Date() { delete c; } string string_rep() const; }; inline string Date::string_rep() const { if (!c->valid) { computer_cache_value(); c->valid = false; } return c->rep; } int main() { Date d; const Date cd; cout << d.string_rep() << endl; cout << cd.string_rep() <<endl; return 0; }