I am trying to make a graph but when I am compiling my code I get the error mentioned in the title, and I can't figure out what the problem is. This is my code so far:
Header:
Code:
#include <iostream>#include <string>
#include <vector>
#include <cstdlib>
class Node{
std::vector<Node*> neighbours;
std::string name;
public:
Node(){};
~Node(){};
std::string node_getName(void){return name;}
void node_setName(std::string p_name){name = p_name;}
std::vector<Node*>* node_getNeighbours(void){return &neighbours;}
};
class Graph{
std::vector<Node*> nodes;
public:
Graph(){};
~Graph(){};
std::vector<Node*>* graph_getNodes(void){return &nodes;}
unsigned int graph_getNbrNodes(void){return nodes.size();}
void graph_insertNode(std::string p_name);
void graph_insertEdge(Node* p_node1, Node* p_node2);
Node* graph_chooseNode(std::string p_name);
};
Source:
Code:
#include "graph.h"
void Graph::graph_insertNode(std::string p_name){
std::vector<Node*>* graphNodes = graph_getNodes();
unsigned int nbrNodes = graph_getNbrNodes();
for (int i = 0; i < nbrNodes; i++){
if (!p_name.compare(graphNodes->at(i)->node_getName())){
return;
}
}
Node newNode;
newNode.node_setName(p_name);
graphNodes->push_back(&newNode);
}
void Graph::graph_insertEdge(Node* p_node1, Node* p_node2){
p_node1->node_getNeighbours.push_back(p_node2);
p_node2->node_getNeighbours.push_back(p_node1);
}
Node* Graph::graph_chooseNode(std::string p_name){
std::vector<Node*>* graphNodes = graph_getNodes();
unsigned int nbrNodes = graph_getNbrNodes();
for (int i = 0; i < nbrNodes; i++){
if (!p_name.compare(graphNodes->at(i)->node_getName())){
return graphNodes->at(i);
}
}
}
This is the error I get:
Anyone understanding what's wrong?