CMapStringToOb::RemoveKey
BOOL RemoveKey( LPCTSTR key );
返回值:
如果发现了入口并成功地删除,则返回非零值,否则为0。
参数:
说明:
查找与提供的关键码对应的映射入口,并在发现该关键码后,删除该入口。如果没有在别处删除CObject对象,那么可能导致内存出现空洞。
示例:
请参阅CObList::CObList,了解所有收集示例中使用的CAge类。
// example for CMapStringToOb::RemoveKey
CMapStringToOb map;
map.SetAt( "Bart", new CAge( 13 ) );
map.SetAt( "Lisa", new CAge( 11 ) );
map.SetAt( "Homer", new CAge( 36 ) );
map.SetAt( "Marge", new CAge( 35 ) );
map.RemoveKey( "Lisa" ); // Memory leak: CAge object not deleted.
#ifdef _DEBUG
afxDump.SetDepth( 1 );
afxDump << "RemoveKey example: " << &map << "\n";
#endif
该程序的结果如下:
RemoveKey example: A CMapStringToOb with 3 elements
[Marge] = a CAge at $49A0 35
[Homer] = a CAge at $495E 36
[Bart] = a CAge at $4634 13
请参阅:CMapStringToOb::RemoveAll