Guest User

Untitled

a guest
Dec 21st, 2017
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. struct Point {
  5. int x;
  6. int& xref = x;
  7. };
  8.  
  9. void printPoints(std::vector<Point>& vec) {
  10. for (int i = 0; i < vec.size(); i++) {
  11. printf("%d: %d %s %d\n", i, vec[i].x, vec[i].x == vec[i].xref ? "==" : "!=", vec[i].xref);
  12. }
  13. printf("\n");
  14. }
  15.  
  16. int main() {
  17. std::vector<Point> points;
  18. for (int i = 0; i < 4; i++) {
  19. Point p;
  20. p.x = i;
  21. points.push_back(p);
  22. // assert (points[0].x == points[0].xref);
  23. printf("After iteration %d:\n", i);
  24. printPoints(points);
  25. }
  26.  
  27. return 0;
  28. }
  29.  
  30.  
  31.  
  32. /* OUTPUT:
  33. After iteration 0:
  34. 0 == 0
  35.  
  36. After iteration 1:
  37. 0 != 1
  38. 1 == 1
  39.  
  40. After iteration 2:
  41. 0 != 2
  42. 1 != 2
  43. 2 == 2
  44.  
  45. After iteration 3:
  46. 0 != 3
  47. 1 != 3
  48. 2 != 3
  49. 3 == 3
  50. */
Advertisement
Add Comment
Please, Sign In to add comment