|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <iostream>
#include <string>
class student;
template <typename T, class fun>
int my_count_if(T *a,int n,fun f) //f 是判断特征的函数
{
int count = 0;
for ( int i=0; i<n; ++i )
{
if (a[i].f)
{
count ++;
}
}
return count ;
}
class student
{
private:
int score;
std::string name;
public:
student(int a=0,char* s="")
:score(a),name(s){}
student (const student& s)
{
if (this!=&s)
{
this->name=s.name;
this->score=s.score;
}
}
student &operator=(const student&rhs)
{
if (this!=&rhs)
{
this->name=rhs.name;
this->score=rhs.score;
}
return *this;
}
bool bujige() //定义不及格的函数
{
return score<60;
}
};
int main()
{
student a[]={student(50,"tom"),student(49,"jerry"),student(91,"henry")};
int n=sizeof(a)/sizeof(*a);
int num=my_count_if(a,n,student::bujige);
}
求大神!!
|
|