我试图通过使用排序谓词创建类指针的向量自定义排序的向量:麻烦建立在C自定义排序++的指针
struct sort_by_airtime
{
inline bool operator() (const Network *n1, const Network *n2)
{
return (n1->airtime() < n2->airtime());
}
};
对于每一个网络,我们的排序由float由airtime()返回。
现在,我尝试使用这个如下:
std::vector<Network *> Simulator::sort_networks(std::vector<Network *> netlist, bool sort_airtime) {
std::vector<Network *> new_netlist = netlist;
if(sort_airtime) {
sort(new_netlist.begin(), new_netlist.end(), sort_by_airtime());
}
}
但是,我得到了很多的错误是这样的:
In file included from Simulator.cpp:7:
Simulator.h: In member function ‘bool Simulator::sort_by_airtime::operator()(const Network*, const Network*)’:
Simulator.h:48: error: passing ‘const Network’ as ‘this’ argument of ‘virtual float Network::airtime()’ discards qualifiers
Simulator.h:48: error: passing ‘const Network’ as ‘this’ argument of ‘virtual float Network::airtime()’ discards qualifiers
我不是指定传递给谓词正确的说法?通话时间()由继承网络类的类实现。
当您在类(或结构体)中定义函数时,不需要明确地说'内联'。 – 2011-12-21 19:29:12