类别边缘列表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); } //*/ }; struct顶点 { 双x,y; }; 阶级边缘主义者 { 私人: std::映射图_容器; 公众: void add_vertex(const vertex&v){//向贴图添加顶点 graph_container.insert(对(v,vector()); } //* void add_边(常数顶点&v,常数顶点&u){//在地图中查找顶点 autoit=graph\u container.find(v); if(it!=graph_container.end()) *它。推回(u); } //*/ };
第一个错误是类别边缘列表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); } //*/ }; struct顶点 { 双x,y; }; 阶级边缘主义者 { 私人: std::映射图_容器; 公众: void add_vertex(const vertex&v){//向贴图添加顶点 graph_container.insert(对(v,vector()); } //* void add_边(常数顶点&v,常数顶点&u){//在地图中查找顶点 autoit=graph\u container.find(v); if(it!=graph_container.end()) *它。推回(u); } //*/ };,c++,class,c++11,graph,C++,Class,C++11,Graph,第一个错误是 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 st
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; }
64-w64-mingw32/include/c++/iostream:39,
来自EarTr.cpp:1:
C:/mingw-w64/x86\u 64-5.2.0-win32-seh-rt\u v4-rev0/mingw64/x86\u 64-w64-mingw32/includ
e/c++/bits/stl_函数。h:387:20:注意:'const vertex'不是从'co'派生的
nst标准::uu cxx11::基本字符串'
{返回{uuuux<\uuuy;}
我在结构中添加了两个函数
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);
}
而不是
*it.push_back(u);
当发布关于构建错误的问题时,请包括您得到的实际错误。完整的,完整的,包括可能的信息注释。只需将文本(作为文本)复制粘贴到问题正文中。然后在源代码(最好是a)上标记错误所在的注释。但您可能应该从了解开始。表达式
*it.push_back(u)
的作用与您认为的不同。
*it.push_back(u);