fork(2) download
  1. #include <iostream>
  2.  
  3. class A {
  4. static int counter = 0;
  5. public:
  6. A();
  7. int getCounter() { return counter; }
  8. };
  9.  
  10. A::A() {
  11. counter++;
  12. }
  13.  
  14. int main()
  15. {
  16. A obj;
  17.  
  18. std::cout << obj.getCounter() << std::endl;
  19.  
  20. return 0;
  21. }
  22.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:4:20: error: non-const static data member must be initialized out of line
        static int counter = 0;
                   ^         ~
1 error generated.
stdout
Standard output is empty