gpt4 book ai didi

c++ - STL 集的 = 运算符问题

转载 作者:行者123 更新时间:2023-11-27 23:31:49 25 4
gpt4 key购买 nike

我在使用以下代码时遇到错误。当我在下面显示的代码的最后调用 detect_H_conflictsdetect_L_conflicts 并将 = 运算符与 msg.conflict_list_H 和 msg.conflict_list_L 一起使用时,问题就出现了。错误是

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

}

最佳答案

您尝试分配给 conflict_list_Hconflict_list_L 成员的名称 msg 是一种类型;我想你的意思是 message (你的对象)。

关于c++ - STL 集的 = 运算符问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4778431/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com