fork download
  1. #include <iostream>
  2.  
  3. namespace One {
  4. namespace Two {
  5.  
  6. class ExampleClass {
  7. public:
  8.  
  9. // static members can be accessed without a class being instantiated
  10. static int i;
  11. };
  12.  
  13. }
  14. }
  15.  
  16. // they also need to be defined outside the class
  17. int One::Two::ExampleClass::i = 500;
  18.  
  19. int main()
  20. {
  21. std::cout << One::Two::ExampleClass::i << std::endl;
  22. }
  23.  
Success #stdin #stdout 0.02s 2724KB
stdin
Standard input is empty
stdout
500