By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,194 Members | 838 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,194 IT Pros & Developers. It's quick & easy.

RWTPtrSlist core dumps, while removing entries.

P: n/a
#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..
}
catch(...)
{
cout << "here" <<endl;
}
return 0;

Jun 13 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Neha 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..
}
catch(...)
{
cout << "here" <<endl;
}
return 0;


We don't know anything about RWTPtrSlist<> since it is not a standard
class. If you wrote it, show us that class and its implementation, or
if you didn't, ask the vendor of the library.

Cheers! --M

Jun 13 '06 #2

P: n/a
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
Jun 13 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.