I have a struct called Node. Node accepts a double and stores it into a variable named value
.
I'm trying to make a new struct. My first example works, but the second doesn't. The second example doesn't give a compiler error and it builds just fine, but when I try to access a value from the node later on, it gives me -9.25596e+061
.
This code works fine:
Node *firstNode;
Node *newNode = new Node(value);
firstNode = newNode;
This code doesn't:
Node *firstNode;
Node newNode(value);
firstNode = &newNode;
I could just use the first three lines of code, but I want to know why the other code doesn't work. Is it fundamentally wrong or is the syntax just slightly off?