appg3.cpp 650 B

123456789101112131415161718192021222324252627
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5. class Items
  6. {
  7. double x;
  8. double y;
  9. int m;
  10. public:
  11. Items() : x(0),y(0), m(0){}; // #1
  12. Items (double xx, double yy, int mm): x(xx),y(yy), m(mm){}; // #2
  13. void Show() const { cout << x << ", " << y << ", " << m << endl;}
  14. };
  15. int main()
  16. {
  17. vector<Items> vt(5);
  18. for_each( vt.begin(), vt.end(), [](const Items & i){i.Show();});
  19. vt.push_back( Items(8.2, 2.8, 3)); //
  20. for_each( vt.begin(), vt.end(), [](const Items & i){i.Show();});
  21. vt.emplace_back( 8.2, 2.8, 3); //
  22. for_each( vt.begin(), vt.end(), [](const Items & i){i.Show();});
  23. cin.get();
  24. }