#include
#include
using namespace std;
The class person {
Public:
The person (string name, int age) {
This - & gt; M_name=name;
This - & gt; M_age=age;
}
The person (const person & amp; P) {
This - & gt; M_name=p. _name;
This - & gt; M_age=p. _age;
}
Bool operator<(const person& P) {
Return this - & gt; M_age & lt; P. _age;
}
String m_name;
Int m_age;
};
The class greaterage {
Public:
Boolean operator () (const person & amp; P1, const person& P2) {
Return p1. M_age & gt; P2. M_age;
}
};
Void show (const person & amp; P) {
cout<" The name "& lt;
Void test () {
Vector
The person p1 (" zhang ", 24);
The person p2 (" two ", 27);
Person p3 (" four "zhao, 22);
The person p4 (" that ", 25);
Person p5 (" eight "zhu, 23);
P.p ush_back (p1);
P.p ush_back (p2);
P.p ush_back (p3);
P.p ush_back (p4);
P.p ush_back (p5);
Vector
The person v1 (" eight "zhu, 23);
The person v2 (" two ", 27);
The person v3 (" zhang ", 24);
The person v4 (" two ", 25);
Valerie plame ush_back (v1);
Valerie plame ush_back (v2);
Valerie plame ush_back (v3);
Valerie plame ush_back (v4);
Sort (what exactly do v.begin (), v.e nd (), greaterage ());
Sort (p.b do v.begin (), p.e nd (), greaterage ());
Vector
T.r esize (v. considering ());//this compiler error no match the function for the call to 'person: the person ()'
Set_intersection (what exactly do v.begin (), v.e nd (), p.b do v.begin (), p.e nd (), t.b do v.begin ());
For_each (t.b do v.begin (), t.e nd (), show);
}
Int main () {
The test ();
return 0;
}
CodePudding user response:
Set_intersection should override '==', but the resize () there has been an error, I changed the reserve () is not an error,