fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <memory>
  4.  
  5. using namespace std;
  6.  
  7. class Klasa
  8. {
  9. int value_;
  10. public:
  11. Klasa(int ai)
  12. : value_(ai)
  13. {
  14. cout << value_ << ' ';
  15. }
  16. ~Klasa()
  17. {
  18. cout << '~' << value_ << ' ';
  19. }
  20. int getValue() { return value_; }
  21. };
  22.  
  23.  
  24. int main()
  25. {
  26. cout << "--- start ---\n";
  27.  
  28. Klasa prototype(42);
  29. int len = 10;
  30. shared_ptr<vector<Klasa> > myarray(new vector<Klasa>(len, prototype));
  31. cout << "\n--- array ready ---\n";
  32.  
  33. for (int i = 0; i < myarray->size(); i++)
  34. cout << (*myarray)[i].getValue() << endl;
  35.  
  36. cout << "--- stop ---\n";
  37. }
Success #stdin #stdout 0s 3276KB
stdin
Standard input is empty
stdout
--- start ---
42 
--- array ready ---
42
42
42
42
42
42
42
42
42
42
--- stop ---
~42 ~42 ~42 ~42 ~42 ~42 ~42 ~42 ~42 ~42 ~42