deleting from 2 lists , but only 1 of them

Started by
1 comment, last by iMalc 12 years, 7 months ago


#include "stdafx.h"

#include <list>
using namespace std;
struct St
{
int m;
int l;
};
int _tmain(int argc, _TCHAR* argv[])
{
St* temp = new St;
temp->l = 5;
temp->m = 10;

list <St*> list1;
list <St*>::iterator list1_it;
list <St*> list2;


list1.push_back(temp);
list2.push_back(temp);

list1_it = list1.begin();
delete (*list1_it);
(*list1_it) = NULL;

// break here
// list1 has a NULL in
// list2 has random stuff though , but theey still poining at same thing , how do i make it NULL , with out directly accessing list2 ?
return 0;
}


just by deleting from list1 and making that point to NULL , i want list2 to be NULL for the same entry
Advertisement
You need to set it to NULL if you want it to be NULL. Do you really need two lists? If so, maybe you can make use of smart pointers.

just by deleting from list1 and making that point to NULL , i want list2 to be NULL for the same entry
To do something like that, you'd need to use smart pointers.

Something like shared_ptr in one list and weak_ptr in the other.
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms

This topic is closed to new replies.

Advertisement