| 网站首页 | 业界新闻 | 群组 | 人才 | 技术文章 | 下载频道 | 博客 | 代码贴 | 编程论坛
绝地游戏外挂辅助教学千里之行 始于足下
共有 3059 人关注过本帖
标题:使用accumulate出现error c 2064错误
只看楼主 收藏
鱼游海底
Rank: 1
来 自:中国
等 级:新手上路
帖 子:132
专家分:2
注 册:2015-4-16
结帖率:57.14%
  已结贴   问题点数:20  回复次数:8   
使用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: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:流年
等 级:贵宾
威 望:82
帖 子:2786
专家分:14619
注 册:2014-10-16
  得分:10 

一片落叶掉进了回忆的流年。
2015-10-30 19:01
鱼游海底
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
农民工
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:21
帖 子:109
专家分:639
注 册:2015-8-22
  得分:10 
你这是什么代码?怎么有for_each ?
2015-11-05 08:37







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

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