Please look at this code.
#include <iostream>
#include <list>
using namespace std;
void main()
{
list<int*> m_List;
int* i = new int(1);
m_List.push_back(i);
list<int**> m_pList;
m_pList.push_back(&m_List.front());
list<int*>::iterator iter = m_List.begin();
delete *iter;
*iter = NULL;
cout << *iter << endl;
cout << &*iter << endl;
iter = m_List.erase(iter);
list<int**>::iterator iter2 = m_pList.begin();
cout << **iter2 << endl;
cout << *iter2 << endl;
}
Result :
00000000
00A31A90
DDDDDDDD
00A31A90
&*iter
is equal to *iter2
, but *iter
is not equal to **iter2
.
Please teach me why this happen and how can I solve this.