首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

如何让下面这段程序编译通过啊

2012-03-09 
怎么让下面这段程序编译通过啊???#include iostream#include string#include set#include function

怎么让下面这段程序编译通过啊???
#include <iostream>
#include <string>
#include <set>
#include <functional>
#include <algorithm>

using namespace std;

class Employee
{
public:
  Employee(size_t id = 0, const string& name = " "):_id(id), _name(name) {}
  size_t getID() { return _id; }
private:
  size_t _id;
  string _name;
};

IDLess :public binary_function<Employee, Employee, bool>
{
public:
  bool operator()(const Employee& lhs, const Employee& rhs) const
  {
  return lhs.getID() < rhs.getID();
  }
};

int main()
{
  Employee emp1(2009102344, "蔡小东"), emp2(2009103333, "陈海明"), emp3(2009103504, "李佳涛");
  set<Employee, IDLess> set1;
  set1.insert(emp1);
  set1.insert(emp2);
  set1.insert(emp3);
  for_each(set1.begin(), set1.end(), mem_fun(&Employee::print));
}

[解决办法]

C/C++ code
#include <iostream>#include <string>#include <set>#include <functional>#include <algorithm>using namespace std;class Employee{public:  Employee(size_t id = 0, const string& name = " "):_id(id), _name(name) {}  size_t getID() const { return _id; }  void print() const { cout << _id << " " << _name << endl; }  bool operator < (const Employee &obj) const {return _id < obj._id;}private:  size_t _id;  string _name;};class IDLess :public binary_function<Employee, Employee, bool>{public:  bool operator()(const Employee& lhs, const Employee& rhs) const  {  return lhs.getID() < rhs.getID();  }};int main(){  Employee emp1(2009102344, ", emp2(2009103333, ", emp3(2009103504, ";  set<Employee, IDLess> set1;  set1.insert(emp1);  set1.insert(emp2);  set1.insert(emp3);  for_each(set1.begin(), set1.end(), mem_fun_ref(&Employee::print));} 

热点排行
Bad Request.