|
-
April 10th, 2003, 10:07 AM
#1
STL deque question
Hello all,
I thought when I call erase() method on an STL deque, it is supposed to call the corresponding destructor of the object. However, it does not when I do this. Here is some code to illustrate the problem.
std: eque<Wave *> _wavePool;
std: eque<Wave *>::iterator it;
Wave *wav1 = new Wave("D:\\waves\\v1.wav", true);
Wave *wav2 = new Wave("D:\\waves\\think.wav", true);
_wavePool.push_back(wav1);
_wavePool.push_back(wav2);
it = _wavePool.begin()
Now, if I call...
_wavePool.erase(it);
The wave destructor never gets called. Am I not supposed to put heap pointers in a queue or do I have to do this manually.
Thanks for any help you might give me.
Xargon
-
April 10th, 2003, 10:20 AM
#2
In case of having any container filled with pointers, the container only destroys its copy of the pointer itself but not the object it is pointing to. You have to do this manually...thus
Code:
std::deque<Wave *> _wavePool;
std::deque<Wave *>::iterator it;
Wave *wav1 = new Wave("D:\\waves\\v1.wav", true);
Wave *wav2 = new Wave("D:\\waves\\think.wav", true);
_wavePool.push_back(wav1);
_wavePool.push_back(wav2);
it = _wavePool.begin();
...
// First delete object
delete *it;
// Then delete it from container
_wavePool.erase(it);
-
April 10th, 2003, 10:29 AM
#3
Ahhhhhh, I get it now. Thanks man!
Cheers,
Xargon
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|