I am trying to make a directed graph, So I made a Graph class and it has a private edge struct and a private node struct. I would like my edges to have a node member which is the node that the edge points to, and I would like my nodes to have a list of all edges that lead away from them.
#ifndef DIRECTED_GRAPH_H
#define DIRECTED_GRAPH_H
#include <iostream>
#include <vector>
#include <string>
class Graph {
public:
Graph( const std::string & );
~Graph();
void print();
private:
struct GNode
{
std::string currency_type;
std::vector<GEdge> edges; // line 19
GNode( std::string name ) : currency_type( name ) {}
};
struct GEdge
{
int weight;
GNode * node; // node that the edge is pointed towards
GEdge( int weight, GNode* node ) : weight( weight ), node( node ) {}
};
GNode *source;
std::vector<GNode> nodes;
void add_node( const std::string & currency );
void add_edge( const GNode *& source, const GNode *& destination, int weight );
std::string bellman_ford( const GNode *&source );
};
#include "directed_graph.cpp"
#endif
The problem is, the first struct being declared, in this case GNode
, is not aware that GEdge
exists which is causing the compiler to give me the error
directed_graph.h:19: error: ISO C++ forbids declaration of ‘vector’ with no type
How can I get around this?