/******************************************************************************/ /* */ /* FILE: october.cpp */ /* */ /* Demostrates the effect of the mutable qualifier */ /* =============================================== */ /* */ /* Compiled and tested with Visual Studio .NET 2003 */ /* */ /* V1.00 30-OCT-2003 P. Tellenbach http://www.heimetli.ch/ */ /* */ /******************************************************************************/ #include <iostream> #include <string> using namespace std ; class MutableConst { protected: mutable string str ; public: MutableConst( const char *s ) : str(s) { } void twist( const char *s ) const { string::iterator it = str.begin() ; while( ++it != str.end() ) it = ++str.insert( it, *s++ ) ; } void print() const { cout << str << endl ; } } ; int main() { const MutableConst mc( "Hlowrd!" ) ; mc.twist( "el ol " ) ; mc.print() ; return 0 ; }
Update 31. October 2023
This program compiles and runs without any changes.