Guest User

Untitled

a guest
Jun 23rd, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. class MyClass
  2. {
  3. public:
  4. // some stuff omitted
  5.  
  6. /***
  7. A function which, in itself, is constant and doesn't change the class
  8. ***/
  9. void myFunction( void ) const;
  10. private:
  11. /***
  12. If loaded is true, then internal resources are loaded
  13. ***/
  14. boolean loaded;
  15. };
  16.  
  17. MyClass :: myFunction( void ) const
  18. {
  19. if( !loaded )
  20. {
  21. // do something here
  22.  
  23. loaded = true; /** <-- this violates const **/
  24. }
  25.  
  26. // carry out some computation
  27. }
  28.  
  29. class MyClass
  30. {
  31. public:
  32. void myFunction( void ) const;
  33. private:
  34. mutable boolean loaded;
  35. };
Add Comment
Please, Sign In to add comment