| Article: |
What Is an Iterator in C++, Part 2 | |
| Subject: | Memory leak | |
| Date: | 2008-08-17 12:47:22 | |
| From: | RoelAaij | |
|
Hi,
|
||
Showing messages 1 through 1 of 1.
-
Memory leak
2008-08-17 13:32:56 RoelAaij [View]
|
|
||||||||||||||||||
Women in TechnologyHear us Roar
Showing messages 1 through 1 of 1.
|
||||||||||||||||||
|
||||||||||||||||||
There are actually 2 memory leaks, this is how I fixed them without borking the queue:
I changed popFront into:
T popFront()
{
Node* p = root_;
T val = p->getVal();
root_ = root_->next_;
if(p) delete p;
return(val)
}
and the SQueue destructor into:
~SQueue()
{
while(root_) {
Node* p = root_;
root_ = root_->next_;
delete p;
}
}
Cheers, Roel