2011-01-24 17 views
0

次のコードでエラーが発生しました。問題は、私がdetect_H_conflictsdetect_L_conflictsと呼び出すときに、以下に示すコードの最後に現れ、msgオペレーションをmsg.conflict_list_Hとmsg.conflict_list_Lで使用するときに発生します。エラーは、型でのconflict_list_Hconflict_list_Lメンバーに割り当てるしようとしている名前msgSTLの=演算子の問題

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 

} 
+0

一緒にコードとエラーメッセージを投稿すると、投稿のコードに行情報を追加してみてください。最も簡単な方法では、単にコメントを追加するだけです。//次の行は308です:前にunqualified-idが必要です。 'トークン。これは、他の人がコンパイラがはるかに簡単に文句を言う行にまっすぐ行くのを助けるでしょう。 –

答えて

3

です。代わりにmessage(あなたのオブジェクト)を意味すると思います。

+0

ああ、私は本当に疲れているはずです。 – Bob

+1

タイプとインスタンスを区別する命名規則があれば、この種のエラーを作るのは本当に難しくなります。 – Keith

1

は次のようになります。

message.conflict_list_H = detect_H_conflicts(received_H_colors); 
message.conflict_list_L = detect_L_conflicts(received_all_colors, node_obj[node].l_color); 
関連する問題