At the consturctor Node = new Node[numberOfNodes]; and Edge = new Edge[numberOfEdges]; gives identifier error? what’s the wrong with it ?
typedef struct node
{
int id;
int x;
int y;
} Node;
typedef struct edge
{
int id;
Node node1;
Node node2;
} Edge;
class graph
{
private:
int numberOfNodes;
int numberOfEdges;
int *Node;
int *Edge;
public:
graph(int nodes, int edges)
{
numberOfNodes = nodes;
numberOfEdges = edges;
Node = new Node[numberOfNodes];
Edge = new Edge[numberOfEdges];
}
You have various variable name conflicts, including a conflict between your variable declaration
int* Node, and the typedefNode. Also, you declare your array of nodes as typeint*when it should be typeNode*. You do the same withEdge. Try the following instead:Also, just for the future, the
typedef struct { }idiom is really unnecessary in C++. It’s main purpose was so that C programmers wouldn’t need to constantly have to prefix their struct variables with the wordstruct. But in C++ this isn’t necessary, so there’s generally no real reason to saytypedef struct node { ... } Node;when you can just saystruct Node { ... };. See here for more information.