fork download
  1. #include <iostream>
  2.  
  3. class Foo {
  4. int myindex;
  5. static int c;
  6. public:
  7. Foo() {
  8. myindex = c++;
  9. }
  10. int getMynum() {
  11. return myindex;
  12. }
  13. };
  14. int Foo::c = 0;
  15.  
  16. int main() {
  17. Foo arg[10];
  18. std::cout << arg[7].getMynum() << std::endl;
  19. std::cout << arg[5].getMynum() << std::endl;
  20. std::cout << arg[3].getMynum() << std::endl;
  21. return 0;
  22. }
  23. /* end */
  24.  
  25.  
Success #stdin #stdout 0.02s 2724KB
stdin
Standard input is empty
stdout
7
5
3