So I have a Node struct
struct Node
{
int x = 0;
};
I make 20 Node*
s. My understanding is that Node**
is a pointer to the start of an array that holds pointers to Node
s.
constexpr int mazeSize = 20;
Node** testMaze = new Node * [mazeSize];
After this, I started getting warnings and errors when I tried to do anything with it. Examples:
testMaze[0]->position.x == 0; //->Using uninitialized memory `*testMaze` and
What I understood from this error: *testMaze
is dereferencing the array of pointers, which means it's referring to the first Node
object in that array. If this is the case than how would I initialize it? If I simply created the Node*
as so:
Node* node = new Node;
node->x = 0;
Than it works fine and there is no need to initialize it, so why not with the way I am doing it? I also don't understand how to initialize a struct.
Another examlpe:
testMaze[0]->x == testMaze[1]->x //->Runtime error: Access violation reading error
testMaze[0]->x = 0; //->Runtime error: Access violation writing error
How can I fix these problems? Thanks.