Advertisement
Guest User

Untitled

a guest
Sep 7th, 2022
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. class A {
  5. public:
  6.     int b;
  7.     A() { b = 1; }
  8. };
  9. int main() {
  10.     vector<A*> arr;
  11.     for (int i = 0; i < 10; ++i)
  12.     {
  13.         A* a = new A();
  14.         a->b = i%9;
  15.         arr.push_back(a);
  16.     }
  17.     for (const auto x : arr)
  18.     {
  19.         cout << x->b << endl;
  20.     }
  21.  
  22.     auto it = std::max(arr.begin(), arr.end(), [](const vector<A*>::iterator x, const vector<A*>::iterator y) { return ((*x)->b) < ((*y)->b); });
  23.     cout << (* it)->b << endl;
  24.  
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement