Jump to content
  • Advertisement
Sign in to follow this  
luasitdown

vector need to initialize?

This topic is 4683 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

vector<node*> m_child; the m_child is no data ,it need to initialize ? hot to initialize ? m_child.clear() ? the same problem is map hash_map string etc...

Share this post


Link to post
Share on other sites
Advertisement
It's a vector of pointers, you can be really sure, there is nothing usefull in it in the begining.

Ex:
vector<node*> m_child;
// now m_child.size() == 0

m_child.push_back( new node(somedata1) );
m_child.push_back( new node(somedata2) );
m_child.push_back( new node(somedata3) );
m_child.push_back( new node(somedata4) );

// now m_child[0], ..., m_child[3] have usefull contents




// later
for (vector<node*>::iterator it = m_child.begin(); it != m_child.end(); ++it)
delete *it;
m_child.clear()



See http://www.sgi.com/tech/stl/Vector.html for more details.


shinjin

Share this post


Link to post
Share on other sites
Firstly, thank you for your question. Secondly, in the future, please consider consolidating your questions into one relevant thread rather than making thirty-six different threads to ask thirty-six questions.

Thirdly, there are many ways to initialize a vector. See here for just a few.

Share this post


Link to post
Share on other sites
[smile]Might I also suggest you use google to assist you with translation from your native language to English if possible?[smile]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!