#include "stdafx.h"
#include <iostream>
#include <map>
using namespace Std;
Using Std::map;
Class CA;
typedef map<int,ca*> MAP;
Class CA {
Public
int A;
};
int _tmain (int argc, _tchar* argv[])
{
Map map;
for (int i=0;i<2;i++)
{
ca* PA = new CA;
Pa->a = 1;
Map[i] = PA;
}
Map::iterator it = Map.begin ();
while (It! = Map.end ())
{
ca* PA = it->second;
Delete PA;
PA = NULL; The PA address asks NULL, but the address of the It->second is not NULL, so if there is no erase, the following sentence should be opened in strict sense, so as to avoid the use of empty values within the map.
It->second = NULL;
it + +;
}
it = Map.begin ();
while (It! = Map.end ())
{
ca* PA = it->second;
int a = 0;
it + +;
}
return 0;
}
/*
Here is a review of some of the concepts of C + +:
*PA is the data on the address indicated by the pointer PA.
The PA is the address that the pointer refers to, which is why Pa=null,it->second is not NULL
&PA represents the address of the pointer
*/
C + + pointer essay 1