fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. struct A {
  8. int x;
  9. static bool compare(const A& s1, const A& s2) {
  10. return s1.x < s2.x;
  11. }
  12. A(int z) : x(z) {}
  13. };
  14.  
  15. struct B : public A {
  16. B(int z) : A(z) {}
  17. };
  18.  
  19. int main() {
  20. vector<B> v;
  21. v.push_back(B(1));
  22. v.push_back(B(7));
  23. v.push_back(B(3));
  24. v.push_back(B(6));
  25. v.push_back(B(2));
  26. sort(v.begin(), v.end(), A::compare);
  27. for(int i=0;i!=v.size();i++)
  28. cout << v[i].x << endl;
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0.01s 2860KB
stdin
Standard input is empty
stdout
1
2
3
6
7