dynamic allocation of nodes

hi all,

i want to create a tree-like structure, made up of connected nodes. each node has a mother and a father node, and possibly everal children. all nodes should be allocated dynamically. the problem then becomes the first "root" node.

my solution (which doesn work):
typedef std::shared_ptr<Node> NodeRef;
in the PRIVATE constructor, i check if a NodeRef m_root exists, if not then create one via:
m_root = NodeRef(new Node(args));
that doesnt work, it has something to do with memory (<xmemory> new bla bla i dont really understand)
to create a new node, i want to call a static member "Create" which creates a new node, and makes sure that it is connected to the tree. in case one parent doesnt exist, it will be "root" by default.

any suggestions ?
do i have to make a "Initialize()" + "CleanUp()" call before / after using the node tree ?

by the way:
if i create a shared_ptr<Node>(&m_root), and m_root is created as global variable in .cpp file, the program creashed at the end (maybe because "delete" is called on the address ?)


thanks for any advice !
Last edited on
> tree-like structure
> each node has a mother and a father node
... ¿how's that a tree? explain your structure

> that doesnt work
your description is awful, leaving too many holes
¿why don't simply post the code?

> something to do with memory (<xmemory> new bla bla i dont really understand)
post the error message verbatim.

> call a static member "Create" which creates a new node, and makes sure
> that it is connected to the tree.
¿you will only have one single "tree"?
¿does that limitation provide any benefit?


by the way http://www.cplusplus.com/reference/memory/make_shared/
Last edited on
Topic archived. No new replies allowed.