我遇到以下代码错误。当我在下面显示的代码的末尾呼叫detect_H_conflicts
和detect_L_conflicts
,并在msg.conflict_list_H和msg.conflict_list_L中使用=运算符时,会出现问题。该错误是STL集合= =运算符的问题
Graph.cpp:308: error: expected unqualified-id before '.' token
Graph.cpp:309: error: expected unqualified-id before '.' token
set<int> Graph::detect_H_conflicts(const vector<int>&v) { ... }
set<int> Graph::detect_L_conflicts(const vector<int>&v, int c) { ... }
struct msg { // nested within Graph in Graph.h
int sender; // sender id
int sender_distance; // sender distance to root node
vector<int> neighbor_list; // neighbors
int num_colors; // number of colors currently used by the node; current color will be in [0, num_colors)
int current_color; // color of the node
set<int> conflict_list_H; // colors not to be used by nodes with higher distance in the hierarchy
set<int> conflict_list_L; // colors not to be used by nodes with higher distance in the hierarchy
};
void Graph::dist_cr_algorithm(int root_node, double p, int iterations) {
// some code
msg message;
// some code
// process received messages
if(!node_obj[node].message_list.empty()) {
//cout << "Messages received" << endl;
for(int item = 0; item < node_obj[node].message_list.size(); item++) {
// update distance to root node
if(node_obj[node].message_list[item].sender_distance + 1 < node_obj[node].l_distance)
node_obj[node].l_distance = node_obj[node].message_list[item].sender_distance + 1;
// update dictionary of two-hops neighbors
for(int thn_idx = 0; thn_idx < node_obj[node].message_list[item].neighbor_list.size(); thn_idx++)
node_obj[node].two_hops_n.insert(node_obj[node].message_list[item].neighbor_list[thn_idx]);
// update maximum number of colors, if necessary
node_obj[node].c_max = max(node_obj[node].c_max, node_obj[node].message_list[item].num_colors);
}
// remove node from neighbors list
node_obj[node].two_hops_n.erase(node);
set<int> received_ids;
set<int> tmp_conflicts;
vector<int> received_H_colors;
vector<int> received_all_colors;
for(int item = node_obj[node].message_list.size()-1; item >= 0 ; item--) {
if(received_ids.find(node_obj[node].message_list[item].sender) == received_ids.end()) {
// most recent message from this sender
received_ids.insert(node_obj[node].message_list[item].sender);
// add H conflicts
for(set<int>::iterator IT = node_obj[node].message_list[item].conflict_list_H.begin();
IT != node_obj[node].message_list[item].conflict_list_H.end(); IT++)
tmp_conflicts.insert(*IT);
// add L conflicts if item has lesser distance
if(node_obj[node].message_list[item].sender_distance < node_obj[node].l_distance) {
for(set<int>::iterator IT = node_obj[node].message_list[item].conflict_list_L.begin();
IT != node_obj[node].message_list[item].conflict_list_L.end(); IT++)
tmp_conflicts.insert(*IT);
}
// also add its color
if(node_obj[node].message_list[item].sender_distance <= node_obj[node].l_distance) // check this
tmp_conflicts.insert(node_obj[node].message_list[item].current_color);
//
if(node_obj[node].message_list[item].sender_distance < node_obj[node].l_distance)
received_H_colors.push_back(node_obj[node].message_list[item].current_color);
received_all_colors.push_back(node_obj[node].message_list[item].current_color);
}
}
// try to resolve conflicts
if(tmp_conflicts.size())
// and change color if possible
node_obj[node].l_color = resolve_conflict(tmp_conflicts, node_obj[node].l_color, node_obj[node].c_max);
// detect H conflicts
msg.conflict_list_H = detect_H_conflicts(received_H_colors);
msg.conflict_list_L = detect_L_conflicts(received_all_colors, node_obj[node].l_color);
// clear the message list
node_obj[node].message_list.clear();
}
// other code
}
在发布代码和错误消息一起,尝试将行信息添加到发布的代码。以最简单的方式,只需添加一个注释`/ /以下是第308行:预期的非限定id之前'。 token`。这将帮助其他人直接进入编译器更容易投诉的行。 – 2011-01-24 08:39:59