I have an incomplete graph with a lot of functions not implemented yet.
It's a graph of adjacent list. It has vertices and edges. I got an error which I cannot understand. Can you explain how the error had come about? The error is
C:\Users\jialee\Documents\CodeBlocks\ShortestPath\Graph.cpp: In constructor 'Edge::Edge(Vertex, Weight)': C:\Users\jialee\Documents\CodeBlocks\ShortestPath\Graph.cpp:34:33: error: no matching function for call to 'Vertex::Vertex()'
And the code is
#include <forward_list>
#include <string>
using namespace std;
const int MAX_SIZE = 10000;
typedef int Weight;
class Vertex {
public:
Vertex(string name, int num);
string city_name;
int city_num;
};
class Edge{
public:
Edge(Vertex v, Weight w);
Vertex associated_vertex;
Weight weight;
};
class Graph{
public:
Graph(int size);
};
Vertex::Vertex(string name, int num){
city_name = name;
city_num = num;
}
Edge::Edge(Vertex v, Weight cost){
associated_vertex = v;
weight = cost;
}
Graph::Graph(int size = MAX_SIZE){
forward_list<Edge> G[size];
}
The error says that you are missing a default constructor (constructor with no arguments) for Vertex, which is required during construction of edge.
Basically, your edge constructor tries to first default initialize all members and then assign the passed values.
You can either add a default constructor to your vertex class or (better) use initializer lists in your edge constructor:
Edge::Edge(Vertex v, Weight cost):
associated_vertex{v},
weight{cost}
{ }