Hi - I am new to using vectors as an array. They seem to be pretty good - my only question is when I have something like this:
for( int i = 0; i < m_BlocksInWorld; i++)
{
cBlock* thisBlock;
thisBlock = new cBlock(m_Display);
// Load the info into this block
thisBlock->loadBlocks(File);
// Add it to the array
m_Blocks.push_back(thisBlock);
// Draw it on screen
thisBlock->drawBlock();
}
I am creating a 'new' cBlock each loop - do I ever have to delete these or will my vector handle all that now?
Here is my clean-up code, please let me know if I'm missing anything or something here is unnecessary:
for(int i = 0; i < m_BlocksInWorld; i++)
{
// Loop through each block and erase it
m_Blocks[i]->clearBlock(m_bg);
m_Blocks[i] = NULL;
}
m_Blocks.clear();
m_Blocks.resize(0);
m_BlocksInWorld = 0;
In that loop I tried a
delete m_Blocks[i]
, but that caused a crash. Thanks for reading my question
I know it's not a critical question but hopefully you can appreciate I'm trying to tidy up memory behind me
Edit: cries at the html gobbling up his tags
Edit2: More crying
[edited by - jaggy on April 21, 2004 10:56:01 AM]