| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 465 人关注过本帖
标题:求助大神 !! 类函数模板 用函数做参数提示 student::bujige”: 非静态成员 ...
取消只看楼主 加入收藏
滚落的石子
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2013-11-20
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:2 
求助大神 !! 类函数模板 用函数做参数提示 student::bujige”: 非静态成员函数的非法调用
#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);
}

//其中bujige是作为一个判定性质的函数
搜索更多相关主题的帖子: private include public return count 
2013-11-20 17:10
滚落的石子
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2013-11-20
收藏
得分:0 
回复 4楼 rjsp
谢谢啊
2013-11-23 17:59
滚落的石子
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2013-11-20
收藏
得分:0 
回复 3楼 yuccn
恩恩
2013-11-23 17:59
快速回复:求助大神 !! 类函数模板 用函数做参数提示 student::bujige”: 非静 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011343 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved