Click here to Skip to main content
15,878,945 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi to all.
What is the problem? why? :-?

C++
std::vector<int>** indexes = new std::vector<int>*[8];
for(int i = 0; i < 8; i++)
{
    indexes[i] = new std::vector<int>[8];
}

//statments...

for(int i = 0; i < 8; i++)
{
    //problem is here !!!
    //Debug Assertion Failed!
    //expression : _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
    delete indexes[i];
}
delete indexes;
Posted
Comments
Andreas Gieriet 3-Jan-13 16:32pm    
Having a variable of type std:vector<int>** look dubious.
I suggest to revisit your data type design.
Your immediate question is well answered by CPallini in Solution#2, but the root cause of your problem is probably your data type implementation as highlighted by H.Brydon in solution#4.
Cheers
Andi

Quote:
delete indexes[i];

you forgot to delete[] on the array of objects, use:
C++
delete [] indexes[i];
 
Share this answer
 
Comments
__UFNHGGI_H__ 3-Jan-13 5:19am    
heeeeeeeeeeeeeeee.
thanks 1tera byte! :D
CPallini 3-Jan-13 5:23am    
You are welcome.
In my opinion, already the allocation is wrong:
indexes[i] = new std::vector<int>[8];

When I understand your code correctly, you want each cell indexes[i] to point to a std::vector<int>. So it should be:
indexes[i] = new std::vector<int>;

And of course, CPallini is right in that you should apply array brackets when finally deleting indexes. But this is not the problem that threw the assertion.
 
Share this answer
 
v2
Comments
Philippe Mori 3-Jan-13 22:01pm    
Or maybe new std::vector<int>(8); if you want an array with an initial size of 8 elements.
Looks like you want a 2D array. I would suggest instead something like:

C++
std::vector<std::vector<int>> indexes;

//statements...


and then you don't need to worry about the memory management. That is one of the main purposes of std::vector.

If you want a 3D array, then:

C++
std::vector<std::vector<std::vector<int>>> indexes;

//statements...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900