fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Hello {
  5. public:
  6. static int myCount;
  7. void test(){
  8. //do nothing
  9. };
  10. Hello(){
  11. Hello::myCount += 1;
  12. };
  13. ~Hello() {
  14. Hello::myCount -= 1;
  15. }
  16. };
  17.  
  18. int Hello::myCount;
  19.  
  20.  
  21. int main(int argc, const char * argv[]) {
  22. // insert code here...
  23. Hello *p1 = new Hello();p1->test();
  24. Hello *p2 = new Hello();p2->test();
  25. cout << Hello::myCount;
  26.  
  27. return 0;
  28. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
2