fork(5) download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. class Foo
  6. {
  7. public:
  8. int a;
  9. int Index;
  10.  
  11. Foo(int _x) : a(_x), Index(-1) {}
  12. Foo(const Foo &_f) : a(_f.a) { Index = ++(const_cast<Foo&>(_f).Index); }
  13. };
  14.  
  15. int main()
  16. {
  17. int a = 5;
  18. std::vector<Foo> Instances (30, a);
  19.  
  20. for(auto &f : Instances)
  21. cout << f.Index << ' ';
  22.  
  23. return 0;
  24. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29