fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. class Point
  5. {
  6. public:
  7. float x, y, z;
  8. };
  9.  
  10. int main() {
  11. std::vector<Point> vect;
  12. Point point_;
  13.  
  14. int num_instances = 5;
  15.  
  16. for (int i = 0; i < num_instances; i++)
  17. {
  18. vect.push_back(point_);
  19. }
  20.  
  21. vect[0].x = 1.0f;
  22. vect[1].x = 2.0f; // if they were the same instance, both x would be set to 2.0f
  23.  
  24. // as you will see, they are separate values
  25. std::cout << vect[0].x << " " << vect[1].x << std::endl;
  26.  
  27. return 0;
  28. }
Success #stdin #stdout 0s 3228KB
stdin
Standard input is empty
stdout
1 2