Sign In/My Account | View Cart  

advertisement

AddThis Social Bookmark Button

Article:
  What Is an Iterator in C++, Part 2
Subject:   Memory leak
Date:   2008-08-17 13:32:56
From:   RoelAaij
Response to: Memory leak

Ok, that was rather silly, scratch that last comment, I can't delete it myself, unfortunately


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