【发布时间】:2016-05-14 21:55:19
【问题描述】:
我只是尝试使用 C++ 中的向量、列表和类来实现有向加权图,但是我收到了这个错误。它给我这个错误的行是第 42:21 行,其中graph[u].push_back(edge(v, w));
#include <iostream>
#include <vector>
#include <list>
#include <stack>
using namespace std;
class edge
{
private:
int cost;
int vertex;
public:
edge(int vertex, int cost)
{
this->vertex = vertex;
this->cost = cost;
}
int getVertex() const
{
return vertex;
}
int getCost() const
{
return cost;
}
};
class Graph
{
private:
int V;
std::vector<std::list<edge> > *graph;
public:
Graph(int V);
void addEdge(int u, int v, int w);
void DFS();
};
Graph::Graph(int V)
{
this->V = V;
graph = new std::vector<std::list<edge> >(V);
}
void Graph::addEdge(int u, int v, int w)
{
graph[u].push_back(edge(v, w));
}
int main()
{
return 0;
}
感谢您的帮助!
【问题讨论】: