Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MyClass
- {
- public:
- // some stuff omitted
- /***
- A function which, in itself, is constant and doesn't change the class
- ***/
- void myFunction( void ) const;
- private:
- /***
- If loaded is true, then internal resources are loaded
- ***/
- boolean loaded;
- };
- MyClass :: myFunction( void ) const
- {
- if( !loaded )
- {
- // do something here
- loaded = true; /** <-- this violates const **/
- }
- // carry out some computation
- }
- class MyClass
- {
- public:
- void myFunction( void ) const;
- private:
- mutable boolean loaded;
- };
Add Comment
Please, Sign In to add comment