E
E. Robert Tisdale
Casper said:I've been told that structs, being value types,
always reside on the stack and, thus,
need not be deleted manually but simple go out of scope in due time.
I have also read that all C++ *new* keywords
must be coupled with an eventual *delete* to free the memmory again.
My question then is, if I create instances of a struct with the new
keyword, which of the above is correct?
Example:
struct tree {
struct tree *parent;
struct tree *child;
String itemData;
};
tree* prootNode = new tree;
tree* psubNode = new tree;
prootNode->child = psubNode;
psubNode->parent = prootNode;
// ...etc...
struct tree rootNode;
struct tree subNode;
rootNode.child = &subNode;
subNode.parent = &rootNode;
Both rootNode and subNode are automatically destroyed
when the thread of execution passes out of the scope
where rootNode and subNode were defined.