On 12 Jun 2006 20:14:25 -0700, "Neha" <ne********@gmail.com> wrote:
#include <rw/tpslist.h>
#include <iostream>
using namespace std;
int main(){
RWTPtrSlist<int> dates;
dates.insert(new int(2)); // 6/2/52
dates.insert(new int(2)); // 6/2/52
// Remove in reverse order:
try
{
while (dates.get()); // When no more entries are there in
list.. it crashes..
The Rogue Wave library is off topic but the general approach how to
tackle such a problem is probably on topic:
1. Read the manual:
http://www.roguewave.com/support/doc...t.html#idx3150
The function get() "Removes and returns the first element in the
collection". The description does not tell you that it checks for an
empty list and that it returns NULL in case of an empty list. So
probably you have to do that. Also your comment ("// Remove in reverse
order") is probably wrong.
2. Write a short unit test to verify your assumption:
RWTPtrSlist<int> dates;
dates.insert(new int(2));
dates.insert(new int(2));
int i = 0;
while (!dates.isEmpty()) {
int* p = dates.removeLast();
++i;
delete p;
}
assert (i == 2);
assert (dates.isEmpty());
BTW, both your pogram and Rogue Waves example contain memory leaks.
Best wishes,
Roland Pibinger