2017-04-22 1 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); 
} 

에이 개 기능을 추가 한

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

하지만 [* 연산자 우선 순위 *] (http://en.cppreference.com/w/cpp/language/operator_precedence)에 대해 배우기 시작해야합니다. '* it.push_back (u) '표현은 당신이 생각하는대로하지 않습니다. –

답변

0

입니다. 에 대해 당신이 얻을 실제 오류를 포함하십시오 다음 빌드 오류 질문을 게시 할 때 또한 나는

it->second.push_back(u); 

대신

*it.push_back(u);