我有一个用户定义的类Node
,一个 typedef ,并试图通过将指针指向包含 .hash_map 的元素VERTEX
来填充 的向量。问题是当我尝试将指针指向迭代器时,会出现一个错误,告诉我“迭代器类型不兼容”。这样做的正确方法是什么?VERTEX*
VERTEX
class Node
{
public:
Node(){DEGREE = 0;}
bool HAS_OUTLINK;//using size() instead
vector <int> IN;
vector <int> OUT;
//string URL;//not strictly necessary
double PAGE_RANK;
double I_A;
int DEGREE;//referring to outdegree
};
typedef pair <int, Node> VERTEX;
void top_ten (hash_map<int, Node>& G){
vector <VERTEX*> top10;// then after some initilisation...
hash_map <int, Node>::iterator i;
for (i = G.begin(); i != G.end(); i++){
for (int j = 0; j < 10; j++){
double &temp = i->second.PAGE_RANK;
VERTEX *compare = top10[j];
if (compare->second.PAGE_RANK < temp){
compare->first = i->first;
compare->second = i->second;//where the mistake is
}
}
}
}
我也尝试过简单地使用compare = i
,compare = &i
尽管编译器都不接受这些。