I have a vertex class that has an id and adjacency list as private members. The adjacency list is stored as a map. When I instantiate an object of this class I want to create an empty map. I am switching over from python to C++ and its proving harder than I thought. Here's the code for the class:
#include "vertex.h"
class Vertex {
char _id;
std::map<char, int> _adjList;
public:
void addNeighbor(Vertex, char neighbor, int weight);
std::vector<char> getConnections(Vertex);
char getId();
int getWeight(Vertex, char neighbor);
Vertex(char);
};
Vertex::Vertex(char id){
std::map<char, int> adjList;
_adjList = adjList;
_id = id;
}
void Vertex::addNeighbor(Vertex v, char neighbor, int weight){
v._adjList.insert(std::map<char, int>::value_type(neighbor, weight));
}
std::vector<char> Vertex::getConnections(Vertex v){
std::vector<char> ids;
for(std::map<char,int>::iterator it = v._adjList.begin(); it != v._adjList.end(); ++it) {
ids.push_back(it->first);
};
return ids;
}
char Vertex::getId(){
return _id;
}
int Vertex::getWeight(Vertex v, char neighbor){
return v._adjList[neighbor];
}
Now when I instantiate this in main
Vertex V('a');
The compiler throws an error that the variable has incomplete type Vertex. Any help is greatly appreciated. Basically I want to construct an object with an id and empty map that will hold the id and path weight to the adjacent node. I am doing this for learning purposes
My vertex.h has:
#ifndef __graphs__vertex__
#define __graphs__vertex__
#include <stdio.h>
#include <map>
#include <vector>
class Vertex;
#endif
and then in my main I include vertex.h