I the compiler is giving me the following error on the constructor of graph however it has been defined in the public section. Error
/tmp/ccku0faq.o: In function `Graph::Graph()':
Main.cpp:(.text._ZN5GraphC1Ev[Graph::Graph()]+0x39): undefined reference to `AdjacencyMatrix::AdjacencyMatrix()'
collect2: ld returned 1 exit status
Here is my code
class Graph {
private:
vector<Node*> nodeList;//list of verticies
bool foundCycle;//true if a cycle is found, false otherwise
int desiredCycSize;
AdjacencyMatrix adjMatrix;
void clearVisited() {
for(int i = 0; i < nodeList.size() && !foundCycle ; i++) {
nodeList[i]->setStatus(NOT_VISITED);
}
}
void addNewNode(Node *nNode) {
nodeList.push_back(nNode);
}
Node* findNodeByName(int name) {
for(int i = 0 ; i < nodeList.size() ; i++) {
if(nodeList[i]->getName() == name)
return nodeList[i];
}
return NULL;
}
Node* findNodeByIndex(int index) {
return nodeList[index];
}
public:
Graph() {
foundCycle = false;
}
~Graph() {
//free mem allocated to verticies
for(int i=0 ; i < nodeList.size() ; i++)
delete nodeList[i];
nodeList.clear();
}
void displayGraph() {
for(int i=0 ; i < nodeList.size() ; i++) {
nodeList[i]->displayList();
}
}
void printMatrix() {
adjMatrix.print();
}
bool readData(string fileName) {
ifstream istream;
istream.open(fileName.c_str());
if(istream.is_open()) //check to make sure the file opened
return false; //file didnt open properly
int graphSize;
istream >> graphSize;
adjMatrix.changeSize(graphSize); //set size of Adjacency Matrix
for(int i = 0; i < graphSize; i++) { //populate the nodeList vector with all the nodes
Node* newNode = new Node(i);
addNewNode(newNode);
}
//graph is garunteed to have a perfect square number of vertices
//DOORS LISTED IN ORDER: NORTH, EAST, SOUTH, WEST, FOR EACH ROOM
for(int i = 0; i < graphSize; i++) {
if(istream.get() == '1') { //check North
findNodeByIndex(i)->addAdjNode(findNodeByIndex((int)(i - sqrt((double)graphSize))));
adjMatrix.addAdjToMatrix(i, (int)(i - sqrt((double)graphSize)));
}
if(istream.get() == '1') { //Check East
findNodeByIndex(i)->addAdjNode(findNodeByIndex(i++));
adjMatrix.addAdjToMatrix(i, i++);
}
if(istream.get() == '1') { //Check South
findNodeByIndex(i)->addAdjNode(findNodeByIndex((int)(i + sqrt((double)graphSize))));
adjMatrix.addAdjToMatrix(i, (int)(i + sqrt((double)graphSize)));
}
if(istream.get() == '1') { //Check West
findNodeByIndex(i)->addAdjNode(findNodeByIndex(i--));
adjMatrix.addAdjToMatrix(i, i--);
}
}
return true; //program executed successfuly
}
};
int main() {
Graph maze;
cout << "Please enter an input file name: ";
string fileName;
cin >> fileName;
maze.readData(fileName);
maze.printMatrix();
return 0;
}
Thanks