怎么在VC6中使用stl的sort函数
如何在VC6中使用stl的sort函数?
在VC6中,使用stl中的sort函数为vector排序,vector中的元素为自定义的struct
在类中自定义了一个private类型的less_second函数
bool less_second(const struct range &x, const struct range &y)
{
return (x.end-x.start) <(y.end-y.start);
}
然后做如下调用
std::sort(t.begin(), t.end(), less_second);
编译报错
error C2664: 'void __cdecl std::sort(struct range *,struct range *,bool (__thiscall *)(const struct range &,const struct range &)) ' : cannot convert parameter 3 from 'bool (const struct range
&,const struct range &) ' to 'bool (__thiscall *)(const struct range &,const struct range &) '
这是怎么回事?
------解决方案--------------------
bool less_second(const range &x, const range &y)
{
return (x.end-x.start) <(y.end-y.start);
}
看行不?
在VC6中,使用stl中的sort函数为vector排序,vector中的元素为自定义的struct
在类中自定义了一个private类型的less_second函数
bool less_second(const struct range &x, const struct range &y)
{
return (x.end-x.start) <(y.end-y.start);
}
然后做如下调用
std::sort(t.begin(), t.end(), less_second);
编译报错
error C2664: 'void __cdecl std::sort(struct range *,struct range *,bool (__thiscall *)(const struct range &,const struct range &)) ' : cannot convert parameter 3 from 'bool (const struct range
&,const struct range &) ' to 'bool (__thiscall *)(const struct range &,const struct range &) '
这是怎么回事?
------解决方案--------------------
bool less_second(const range &x, const range &y)
{
return (x.end-x.start) <(y.end-y.start);
}
看行不?