typedef map<int,myClass*> MYMAP; MYMAP MyMap; MYMAP::iterator MyIter; //here add some elements to MyMap //walk through for(MyIter = MyMap.begin(),MyIter != MyMap.end(); MyIter++) { //access the value in the map; assert(MyIter->second); delete MyIter->second; }
这里用的是map,不是CMap,有没有别的方法?
To:vcmute
begin() end()得到开始和结尾,但如何实现从开始到结尾的遍历,比如得到next?
map<int, myClass *>::iterator pos;
for(pos = coll.begin();pos != coll.end();++pos)
{
p=(*pos).second;
delete p;
}
map<int,myClass*> coll;
MYMAP MyMap;
MYMAP::iterator MyIter;
//here add some elements to MyMap
//walk through
for(MyIter = MyMap.begin(),MyIter != MyMap.end(); MyIter++)
{
//access the value in the map;
assert(MyIter->second);
delete MyIter->second;
}