用STL模板重载时的问题
#include<iostream>
#include<vector>
#include<functional>
#include<algorithm>
#include<iterator>
using namespace std;
class HFTreeNode{
public:
float weight;//节点的权值;
int parent;
int lchild;
int rchild;
char word;
bool operator<(const HFTreeNode& rhs) { return weight < rhs.weight ; }
bool operator>(const HFTreeNode& rhs) { return weight > rhs.weight ; }
};
void main(){
HFTreeNode list[3];
list[0].weight =0.5;
list[0].word ='a';
list[1].weight =0.3;
list[1].word ='b';
list[2].weight =0.4;
list[2].word ='c';
vector<HFTreeNode>vl(list,list+3);
make_heap(vl.begin (),vl.end(),less<HFTreeNode>());
pop_heap(vl.begin (),vl.end());
cout<<"权值最大的为"<<endl;
cout<<(vl.end()-1)->word<<endl;
system("pause");
}
[解决办法]
改成
bool operator<(const HFTreeNode& rhs) const { return weight < rhs.weight ; }
bool operator>(const HFTreeNode& rhs) const { return weight > rhs.weight ; }
试试