fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. struct Location
  5. {
  6. Location(int x, int y)
  7. : x(x)
  8. , y(y)
  9. {
  10. std::cout << "ctor" << std::endl;
  11. }
  12.  
  13. Location(const Location & other)
  14. : x(other.x)
  15. , y(other.y)
  16. {
  17. std::cout << "copy ctor" << std::endl;
  18. }
  19.  
  20. int x;
  21. int y;
  22. };
  23.  
  24. int main ()
  25. {
  26. // local objects
  27. Location locs[3]{ {1, 2}, {3, 4}, {5, 6} };
  28.  
  29. // code that updates locs[0], locs[1], locs[2] ...
  30.  
  31. // construct vector
  32. std::vector<Location> pointsVec {locs, locs+3};
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0s 5504KB
stdin
Standard input is empty
stdout
ctor
ctor
ctor
copy ctor
copy ctor
copy ctor