主题:帮忙那里错啊
#include <iostream>
#include <string>
#include <list>
#include <algorithm>
#include "XR.h"
class Worker
{
private:
std::string id;
char* name;
int age;
double salary;
enum gender{male,female};
public:
Worker (int i=0,char* n=" ",int a,double s=0)
{
id=i;
strcpy(name, n);
age=a;
salary=s;
}
void set(int i, char* n ,int a, double s)
{
id=i;
strcpy(name , n);
age=a;
salary=s;
}
void print(const Worker& w)
{
std::cout<<id<<"\t"<<name<<"\t"<<age<<"\t"<<salary<<"\t";
}
};
bool compBySalary(const Worker& b,const Worker& c)
{
return b.salary > c.salary;
}
int main()
{
Worker w[]={{0905080201,"jodan",male,2000},{0905080202,"mary",female,2500},{0905080203,"jack",male,2600},{0905080204,"tina",female,3000}};
int n=sizeof(w) / sizeof(*w);
std::list<Worker> lw;
for (size_t i=0;i!=n;++i)
lw.push_back(w[i]);
std::for_each(lw.begin(),lw.end(),print);
lw.sort(compBysalary);
Worker w;XRv(w.print());
}
#include <string>
#include <list>
#include <algorithm>
#include "XR.h"
class Worker
{
private:
std::string id;
char* name;
int age;
double salary;
enum gender{male,female};
public:
Worker (int i=0,char* n=" ",int a,double s=0)
{
id=i;
strcpy(name, n);
age=a;
salary=s;
}
void set(int i, char* n ,int a, double s)
{
id=i;
strcpy(name , n);
age=a;
salary=s;
}
void print(const Worker& w)
{
std::cout<<id<<"\t"<<name<<"\t"<<age<<"\t"<<salary<<"\t";
}
};
bool compBySalary(const Worker& b,const Worker& c)
{
return b.salary > c.salary;
}
int main()
{
Worker w[]={{0905080201,"jodan",male,2000},{0905080202,"mary",female,2500},{0905080203,"jack",male,2600},{0905080204,"tina",female,3000}};
int n=sizeof(w) / sizeof(*w);
std::list<Worker> lw;
for (size_t i=0;i!=n;++i)
lw.push_back(w[i]);
std::for_each(lw.begin(),lw.end(),print);
lw.sort(compBysalary);
Worker w;XRv(w.print());
}