自定义数据类型
#include<iostream>
using namespace std;
#include<vector>
#include<string>
#include<algorithm>
class Person
{
public:
Person(string s, int a)
{
this->m_age = a;
this->m_name = s;
}
bool operator==(const Person& p)
{
if (this->m_age = p.m_age)
{
return true;
}
else
{
return false;
}
}
string m_name;
int m_age;
};
class Great20
{
public:
bool operator()(Person p)const
{
return p.m_age > 20;
}
};
void test02()
{
vector<Person>v;
Person p1("asf", 20);
Person p2("aassf", 30);
Person p3("assdff", 20);
Person p4("effasf", 10);
Person p5("aswqerf", 60);
Person p("asasew", 30);
v.push_back(p1);
v.push_back(p2);
v.push_back(p3);
v.push_back(p4);
v.push_back(p5);
//大于20岁
int num = count_if(v.begin(), v.end(), Great20());
cout << "大于20岁人员个数: " << num;
}
int main()
{
test02();
}