merkator

Untitled

Dec 15th, 2011
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cassert>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. struct A { int x, y; };
  8.  
  9. int cnt1 = 0;
  10. int cnt2 = 0;
  11.  
  12. struct ALess
  13. {
  14.   ALess()
  15.   {
  16.     //assert(++cnt1 <= 1);
  17.     printf("ALess #%d created\n", ++cnt1);
  18.   }
  19.  
  20.   bool operator() ( A u, A v ){ return u.y < v.y; }
  21.  
  22.   ~ALess()
  23.   {
  24.     //assert(++cnt2 <= 1);
  25.     printf("ALess #%d destroyed\n", ++cnt2);
  26.   }
  27. };
  28.  
  29. const int n = 10;
  30. A a[n];
  31.  
  32. int main()
  33. {
  34.   ALess *x = new ALess();
  35.   sort(a, a + n, *x);
  36.   return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment