关于自定义的cmp函数报错的问题?
#include <iostream>#include <cstring>
#include <algorithm>
#include <string>
using namespace std;
struct people
{
string sex;
double tall;
};
bool cmp(people a,people b)
{
return a.tall<b.tall;
}
int main()
{
int n;
cin>>n;
people num;
int m=0,k=0;
double num1,num2;
memset(num1,0,sizeof(num1));
memset(num2,0,sizeof(num2));
for(int i=0;i<n;i++)
cin>>num.sex>>num.tall;
for(int i=0;i<n;i++)
{
if(num.sex=="male")
{
num1=num.tall;
m++;
}
if(num.sex=="female")
{
num2=num.tall;
n++;
}
}
sort(num1,num1+m);
sort(num2,num2+n,cmp);
for(double &x:num1)
cout<<x<<" ";
for(double &x:num2)
cout<<x<<" ";
cout<<endl;
return 0;
}
error: could not convert '* __it1' from 'double' to 'people'|
sort(num2,num2+n,cmp);
应该和cmp函数参数类型相同吧 sp1ral 发表于 2018-1-12 10:37
sort(num2,num2+n,cmp);
应该和cmp函数参数类型相同吧
我制杖了,谢谢了
页:
[1]