2017-04-22 15 views
-1

Edge ListクラスをC++で作成しようとしています。 コードをコンパイルするとエラーが多く発生しますが、理解できません。何が間違っていますか?class Edge List C++

struct vertex 
{ 
    double x,y; 
}; 

class EdgeList 
{ 
private: 
    std::map<vertex, vector<vertex>> graph_container; 
public: 

    void add_vertex(const vertex& v) { //add a vertex to the map 
     graph_container.insert(pair<vertex,vector<vertex> >(v, vector<vertex>())); 
    } 
    //* 
    void add_edge(const vertex& v, const vertex& u) { //look up vertex in map 
      auto it = graph_container.find(v); 
      if (it != graph_container.end()) 
       *it.push_back(u); 

    }  
    //*/ 
}; 

最初のエラーは、私はそう、今、マップはデータの私のタイプで作業することができ、構造体

bool operator==(const vertex &o)const { 
    return x == o.x && y == o.y; 
} 

bool operator<(const vertex &o) const{ 
    return x < o.x || (x == o.x && y < o.y); 
} 

に2つの機能を追加しました

64-w64-mingw32/include/c++/iostream:39, 
       from EarTr.cpp:1: 
C:/mingw-w64/x86_64-5.2.0-win32-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/includ 
e/c++/bits/stl_function.h:387:20: note: 'const vertex' is not derived from 'co 
nst std::__cxx11::basic_string<_CharT, _Traits, _Alloc>' 
     { return __x < __y; } 
+0

を使用しています。可能な情報メモを含めて完全な形で記入してください。質問本文にテキスト(*としてテキスト*)をコピーして貼り付けてください。次に、エラーが発生している箇所で、ソース([最小、完全、および検証可能な例](http://stackoverflow.com/help/mcve))をマークします。 –

+0

しかし、あなたは[* operator precedence *](http://en.cppreference.com/w/cpp/language/operator_precedence)について学ぶことから始めるべきでしょう。式 '* it.push_back(u)'は、あなたが思うようなことをしません。 –

答えて

0

です。 はまた、私は

it->second.push_back(u); 

の代わりに、ビルドエラーについての質問を投稿すると、あなたが得る実際の誤差を含めてください

*it.push_back(u);