So, I have two classes: Node and Graph. In the private section of Graph class I declare this:
int size;
Node* n;
In the Graph constructor I'm trying to create a dynamic array:
size=1;
Node *n = new Node[size];
But I'm getting an error: "Access violation reading location 0xcccccd44". How can I fix it? I know that I must be doing something wrong with the array, but I have no idea what and how to fix it.
Class Graph:
class Graph {
friend class Node;
private:
int size;
Node* n;
public:
Graph();
Graph(int, Vertex*);
~Graph();
void Draw(RenderWindow &);
void Update(RenderWindow &, GameObject &, bool);
};
And two constructors:
Graph::Graph() {
size=1;
Node *n = new Node[size];
}
Graph::Graph(int s, Vertex p[]) {
size=s;
Node *n = new Node[size];
for (int i=0; i<size; i++) {
n[i].setNumer(i);
n[i].setX(p[i].getX());
n[i].setY(p[i].getY());
}
}
n, rather than declaring a local variable with the same name? And why aren't you usingstd::vector<Node>to avoid all the problems you get with manual pointer-juggling?n = new Node[size];, you are hiding your member variablen.std::vectoranyway.