#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class Person
{
public:
Person(string name, int age):
name(name),
age(age)
{}
string name;
int age;
};
class Count
{
public:
bool operator()(const Person &p)
{
return p.age > 8;
}
};
int main()
{
Person p1("furong", 10);
Person p2("quange", 8);
Person p3("zhangsan", 20);
vector<Person> v;
v.push_back(p1);
v.push_back(p2);
v.push_back(p3);
int num = count_if(v.begin(), v.end(), Count());
cout << "大于8岁人数 " << num << endl;
return 0;
}
$ ./a.out
大于8岁人数 2