In the book "C + Programming Language", the author has given the following example: "Before using the cache, Need to fill ". I think this is the reason that the function of compute_cache_value has been kept. But I do not understand what implementations of string_rep () do according to its implementation. Thank you for clarification. class date {bool cache_valid; String cache; Zero compute_cache_value (); // fill cache // ... public: // ... string string_rep () const; }; String date :: string_rep () const {if (cache_valid == incorrect) {date * th = console-type & lt; Date & date; (this); // remove cast const-> compute_cache_value (); Th-> cache_valid = true; } Return cash; }
Additionally, the author gave the following for example:
date d1; Call date d2; String s1 = d1.string_rep (); String s2 = d2.string_rep ();
And the author said that the fourth example will display undefined behavior. I would like to know why class = "text">
Comments
Post a Comment