class CStore
{
public:
CObject* GetObject(const std::string& strName)
{
SortAlphabetically();
// Retrieve item "strName" using lower_bound() or equivalent
}
void SortAlphabetically()
{
// Sorts m_storage alphabetically
}
private:
std::vector<CObject*> m_storage;
};
void CStore::DoNothingSpecial() const
{
m_storage.clear();
}
Declaring members mutable is most appropriate when (only) part of a representation is allowed to change. If most of an object changes while the object remains logically const, it is often better to place the changing data in a separate object and access it indirectly.Then, using this design style, he moves the cached Date formatted strings and valid flags to their own class and now mutable is not needed.
ASKER
ASKER
ASKER
C++ is an intermediate-level general-purpose programming language, not to be confused with C or C#. It was developed as a set of extensions to the C programming language to improve type-safety and add support for automatic resource management, object-orientation, generic programming, and exception handling, among other features.
TRUSTED BY
Mutable should be used to enforce the contract that your classes interface exposes. For example, if your class needs to track how many times a function is called but that function is const then making it non-const just to perform this internal house-keeping is violating the contract of the interface for no good reason or benefit to the user of the interface.
Does that make sense?