我正在尝试访问我的嵌套类,以便我可以返回此函数中的对象:
Graph::Edge Graph::get_adj(int i)
{
Graph::Edge v;
int count = 0;
for(list<Edge>::iterator iterator = adjList[i].begin(); count <= i ;++iterator)
{
v.m_vertex = iterator->m_vertex;
v.m_weight = iterator->m_weight;
}
return v;
}
Run Code Online (Sandbox Code Playgroud)
不用担心 for 循环(理论上它应该可以工作)我的主要问题是声明对象Graph::Edge v; 它不起作用!这是我得到的错误:
$ make -f makefile.txt
g++ -Wall -W -pedantic -g -c Graph.cpp
Graph.cpp: In member function `Graph::Edge Graph::get_adj(int)':
Graph.cpp:124: error: no matching function for call to `Graph::Edge::Edge()'
Graph.cpp:43: note: candidates are: Graph::Edge::Edge(const Graph::Edge&)
Graph.h:27: note: Graph::Edge::Edge(std::string, int)
makefile.txt:9: recipe for target `Graph.o' failed
make: *** …Run Code Online (Sandbox Code Playgroud)