A.is there a problem with this handling of this struct ? struct Node { list<Node *> sons; string value; Node(string v);//Constructor for no sons }; |
Function that uses this struct will have: void somefunction(string father, string newval) { Node*place=search(root, father);//search is some function Node *Newp; Newp->value = newval; } B.Is it ok |
Newp
is an uninitialized pointer.every organ is Node by itself and contains a List.. Node *t; t->sons.begin(); |
t
is an uninitialized pointer.C.Is there a problem with this iterator handling and this struct?: void SomeOtherFunction(Node *p, int level) { list<Node *>::iterator it = (*p).sons.end(); *(it--); } |
Newp->value = newval; Newp->sons = { NULL }; |
new
keyword, but in that case you should not forget to delete
the object when you are done with it (or you could use smart pointers).
|
|
C.Is there a problem with this iterator handling and this struct?: |
(*p).sons
is empty you will have an undefined behavior.
|
|