fork download
  1. #include <vector>
  2. #include <iostream>
  3.  
  4. class Vector
  5. {
  6. public:
  7. float x,y;
  8. };
  9.  
  10. int main()
  11. {
  12. // uninitialized grid[0] and grid[1]
  13. std::vector<Vector> grid(2);
  14.  
  15. // (5, 3) stored in grid[2]
  16. // element constructed directly in "grid"
  17. grid.emplace_back(Vector{5.f, 3.f});
  18.  
  19. std::cout << grid[2].x << "," << grid[2].y << '\n';
  20. return 0;
  21. }
  22.  
Success #stdin #stdout 0s 2984KB
stdin
Standard input is empty
stdout
5,3