Accessing a vector of nodes in a node

-------------
Last edited on
Hi,

m_head is a pointer, a.m_children[0] is not. Hence the part of the error message

..... non-class type ‘Node*’


Note the * at the end.

Probably shouldn't be using new and delete, consider std::unique_ptr instead.

Edit:

If you use emplace_back to construct a member of a STL container in place, you won't need to do any dynamic memory. The STL containers store their data on the heap, provided one doesn't have to copy it to get it there (as in push_back)

I guess I am trying to say: do as much as you can with the STL, avoid raw pointers and dynamic memory using new.
Last edited on
Your answer actually gave me the idea I needed to figure it out! Turns out I should have declared the vector as a vector of pointers, not nodes themselves. Thanks for the help!
`a' is a pointer, you need to derefence it to work with the object that it points to
1
2
a->m_children[0];
(*a).m_children[0];


However, as TheIdeasMan pointed out, your vector holds `Node', not `Node*', so you can't assign it to `m_head'
Topic archived. No new replies allowed.