4 ms·
“the count() member function sounds like it should be non-modifying, but in fact it needs to update member data and thus cannot be const” That isn’t correct. J
by Someone 6y ago
“the count() member function sounds like it should be non-modifying, but in fact it needs to update member data and thus cannot be const”
That isn’t correct. Just declare count as mutable. See https://en.cppreference.com/w/cpp/language/cv https://en.cppreference.com/w/cpp/language/cv. Memoization is a valid use case for that feature.