• Advertisement
Sign in to follow this  

deleting from 2 lists , but only 1 of them

This topic is 2348 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts



#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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement