fork download
  1. #include <iostream>
  2.  
  3. class MyClass
  4. {
  5. public:
  6. static int classval;
  7. void foo() {
  8. static int val = 0;
  9. std::cout << ++val << std::endl;
  10. std::cout << ++classval << std::endl;
  11. }
  12. };
  13. int MyClass::classval = 0;
  14.  
  15. int main(void)
  16. {
  17. MyClass *a = new MyClass();
  18. MyClass *b = new MyClass();
  19. a->foo();
  20. b->foo();
  21. a->foo();
  22. b->foo();
  23.  
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0s 2984KB
stdin
Standard input is empty
stdout
1
1
2
2
3
3
4
4