i just started reading about linked list and doing it from scratch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
int main()
{
struct node
{
std::string name;
node *next;
};
node *root;
node *traverser;
root = new node;
root->name = "1";
root->next->name = "2"; // why is this working? it should crash the program
// next node isnt allocated yet.
}
Can you post full code including the above as firstly, it will allow me to run it in the cpp.sh shell, and secondly, you're first example doesn't have _test in it.
How can that be the full code when it doesn't even include int main()? I meant post full compilable code, which will show up as having a small cog icon on the top right when posted.