Skip to main content
gamedev.net
🔒 Locked

vector need to initialize?

Started by luasitdown 2 replies 550+ views
Original Post
luasitdown
luasitdown
vector 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...
cr_shinjin
cr_shinjin
It's a vector of pointers, you can be really sure, there is nothing usefull in it in the begining.

Ex:
vector 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::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
kSquared
kSquared
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.
- k2 "Choose a job you love, and you'll never have to work a day in your life." — Confucius"Logic will get you from A to B. Imagination will get you everywhere." — Albert Einstein"Money is the most egalitarian force in society. It confers power on whoever holds it." — Roger Starr{General Programming Forum FAQ<
iMalc
iMalc
[smile]Might I also suggest you use google to assist you with translation from your native language to English if possible?[smile]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.