I'm currently working on a template graph class that utilizes two vectors to create an adjacency matrix. I can get this to work outside of the template class, but I can't seem to initialize the vectors.
Here is what I have:
#include <stdexcept>
#include <vector>
#include <list>
#include <string>
using namespace std;
namespace GraphNameSpace
{
enum isDirected {DIRECTED, UNDIRECTED};
enum isWeighted {WEIGHTED, UNWEIGHTED};
template <class T>
class Graph
{
public:
Graph<T>();
Graph<T>(isDirected);
Graph<T>(isWeighted);
Graph<T>(isDirected, isWeighted);
Graph<T>(isWeighted, isDirected);
void destroy();
bool isEmpty() const;
bool isFull() const;
bool isAdjacentTo(T fromVertex, T toVertex) const;
int edgeWeight(T fromVertex, T toVertex) const;
int edgeCount() const;
int vertexCount() const;
void insertVertex(T Vertex);
void insertEdge(T fromVertex, T toVertex, int weight);
void deleteVertex(T Vertex);
void deleteEdge(T fromVertex, T toVertex);
int findVertex(T Vertex) const;
void dump() const;
private:
vector<int> colOfRow(100);
vector<vector<int> > matrix(100);
int numVertices;
int numEdges;
static isDirected dir;
static isWeighted wght;
};
}
What is the reason that those will initialize in a separate file, but won't in the template class, and what would a solution to this be? I know this may not be the most efficient way of doing it, but it's the way I understand best. If you would consider another way to be better, would you provide the way you would go about doing this?
