-1
我想在C++上創建邊緣列表類。 當我編譯代碼時,出現很多錯誤,但我不明白,我錯了什麼?類邊緣列表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);
}
//*/
};
第一個錯誤是
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; }
投遞問題有關構建錯誤,那麼請包含您獲得實際的錯誤。完整填寫幷包含可能的信息說明。只需將文本(*作爲文本*)複製粘貼到問題主體中即可。然後標記源代碼(最好是[最小,完整和可驗證示例](http://stackoverflow.com/help/mcve)),其中包含錯誤的註釋。 –
但是,您應該首先了解[*運算符優先級*](http://en.cppreference.com/w/cpp/language/operator_precedence)。表達式'* it.push_back(u)'不會做你認爲它做的事。 –