http://www.cplusplus.com/reference/stl/map/erase/
Erase elements
Removes from the map container either a single element or a range of elements ([first,last)).
This effectively reduces the container size by the number of elements removed, calling each element's destructor.
原话是这么说的,,可是经过实际测试:
#include "stdafx.h"
#include <map>
#include <list>
#include <iostream>
using namespace std;
class A
{
public:
A()
{
}
~A()
{
cout<<"Destructing"<<endl;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
map<int,A*> mapA;
A* pA1 = new A;
mapA.insert(make_pair(1,pA1));
mapA.erase(1);
list<A*> listA;
A* pA2 = new A;
listA.push_back(pA2);
listA.erase(listA.begin());
return 0;
}
发现析构函数并没有调用,看来cpp网站上的STL跟VC中的不是一个版本啊,要么就是我理解有误?