| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3085 人关注过本帖
标题:使用accumulate出现error c 2064错误
取消只看楼主 加入收藏
鱼游海底
Rank: 1
来 自:中国
等 级:新手上路
帖 子:132
专家分:2
注 册:2015-4-16
结帖率:57.14%
收藏
已结贴  问题点数:20 回复次数:6 
使用accumulate出现error c 2064错误
程序代码:
main.cpp
#include <iostream>
#include <algorithm>
#include <functional>
#include <numeric>
#include "Worker.h"
using namespace std;
int main() {
    Worker w[4] = {Worker("1405121101", "zhangsan", 18, male, 8000),
    Worker("1405121102", "lisi", 19, male, 9000),
    Worker("1405121103", "wange", 20, female,10000),
    Worker("1405121104", "xiaoli", 21, female, 9999)};

    cout << "before sort:\n";
    for_each(w, w + 4, mem_fun_ref(&Worker::Print));
    sort(w, w + 4, cmpWorkerBySalary);
    cout << "after sort:\n";
    for_each(w, w + 4, mem_fun_ref(&Worker::Print));

    Worker *p = max_element(w, w + 4, cmpWorkerBySalary);
    cout << "max_salary of :" << p -> GetName() << endl;
    p = min_element(w, w + 4, cmpWorkerBySalary1);
    cout << "min_salary of :" << p -> GetName() << endl;
    cout << "average salary:" << accumulate(w, w + 4, double(0), AddSalary) / 4.0
        << endl;
    if(Man_salary(w, 4) < Woman_salary(w, 4)) cout << "average :man < woman.\n";
    if(Man_salary(w, 4) > Woman_salary(w, 4)) cout << "average :man < woman.\n";
    if(Man_salary(w, 4) == Woman_salary(w, 4)) cout << "average :man < woman.\n";
}
程序代码:
Worker.h
#ifndef WORKER_CLASS
#define WORKER_CLASS
#include <iostream>
#include <string>
using namespace std;
enum Gender {female, male};
class Worker {
private:
    string id;
    string name;
    int age;
    Gender gender;
    double salary;
public:
    Worker(const char* sid = "", const char* sn = "", int na = 0,
        Gender g = female, double sa = 0);
    Worker(const Worker& w);
    Worker& operator = (const Worker& rhs);
    double GetSalary() const {return salary;}
    Gender GetGender() const {return gender;}
    string GetName() const {return name;}

    void Print(ostream& os = cout);
};
bool cmpWorkerBySalary(const Worker& a, const Worker& b);
bool cmpWorkerBySalary1(const Worker& a, const Worker& b);
double AddSalary(double d, const Worker& s);
double Man_salary(Worker *p, int n);
double Woman_salary(Worker *p, int n);
#endif
程序代码:
Worker.cpp
#include <iostream>
#include <numeric>
#include "Worker.h"

bool cmpWorkerBySalary(const Worker& a, const Worker& b) {
    return a.GetSalary() > b.GetSalary();
}
bool cmpWorkerBySalary1(const Worker& a, const Worker& b) {
    return a.GetSalary() < b.GetSalary();
}
double AddSalary(double d, const Worker& s) {
    return d + s.GetSalary();
}
double Man_salary(Worker *p, int n) {
    int m = 0;
    for(int i = 0; i < n; ++i) {
        if((p + i) -> GetGender() == male) ++m;
    }
    return accumulate(p, p + m, double(0), AddSalary) / m; 
}
double Woman_salary(Worker *p, int n) {
    int m = 0;
    for(int i = 0; i < n; ++i) {
        if((p + i) -> GetGender() == female) ++m;
    }
    return accumulate(p, p + m, double(0), AddSalary) / m; 
}
Worker::Worker(const char* sid, const char* sn, int na,
    Gender g, double sa):id(sid), name(sn), age(na),
    gender(g), salary(sa) {}
Worker::Worker(const Worker& w):id(w.id), name(w.name), age(w.age),
    gender(w.gender), salary(w.salary) {}
Worker& Worker::operator = (const Worker& rhs) {
    id = rhs.id;
    name = rhs.name;
    age = rhs.age;
    gender = rhs.gender;
    salary = rhs.salary;
    return *this;
}
void Worker::Print(ostream& os) {
    os << id << "  " << name << "  " << age << "  "
        << gender << "  " << salary << endl;
}
2015-10-29 15:32
鱼游海底
Rank: 1
来 自:中国
等 级:新手上路
帖 子:132
专家分:2
注 册:2015-4-16
收藏
得分:0 
错误信息:  错误    1    error C2064: 项不会计算为接受 1 个参数的函数    c:\program files (x86)\microsoft visual studio 10.0\vc\include\algorithm    22
2015-10-29 15:32
鱼游海底
Rank: 1
来 自:中国
等 级:新手上路
帖 子:132
专家分:2
注 册:2015-4-16
收藏
得分:0 
求大神指导,急救啊!!!
2015-10-29 15:33
鱼游海底
Rank: 1
来 自:中国
等 级:新手上路
帖 子:132
专家分:2
注 册:2015-4-16
收藏
得分:0 
望大神知道啊!!!
2015-10-29 16:03
鱼游海底
Rank: 1
来 自:中国
等 级:新手上路
帖 子:132
专家分:2
注 册:2015-4-16
收藏
得分:0 
再来顶一楼!!!
2015-10-29 21:35
鱼游海底
Rank: 1
来 自:中国
等 级:新手上路
帖 子:132
专家分:2
注 册:2015-4-16
收藏
得分:0 
不要这样!!!难道是大神们觉得这种问题不值一提???
2015-11-01 17:40
鱼游海底
Rank: 1
来 自:中国
等 级:新手上路
帖 子:132
专家分:2
注 册:2015-4-16
收藏
得分:0 
这个程序虽然长,但是比较规范,主要解决的就是类WORKER的一些功能吧!
2015-11-02 11:06
快速回复:使用accumulate出现error c 2064错误
数据加载中...
 
   



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

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