fork download
  1. #include <iostream>
  2.  
  3. class foo
  4. {
  5. public:
  6. void fn();
  7. void fn2();
  8. private:
  9. void check_invariants();
  10. int i = 2; // must be between 0 and 5
  11. };
  12.  
  13. void foo::check_invariants()
  14. {
  15. if (i > 5 || i < 0)
  16. throw("Oops");
  17. }
  18.  
  19. void foo::fn()
  20. {
  21. // do stuff
  22. check_invariants();
  23. }
  24.  
  25. void foo::fn2()
  26. {
  27. // do stuff
  28. check_invariants();
  29. }
  30.  
  31. int main() {
  32. foo f;
  33. f.fn();
  34. f.fn2();
  35. return 0;
  36. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
Standard output is empty