Share via


CMapStringToOb::RemoveKey

搜尋對應項目與所提供之索引鍵對應;然後,因此,如果找到索引鍵,移除項目。

BOOL RemoveKey(
   LPCTSTR key 
);

參數

  • key
    指定用於對應搜尋的字串。

傳回值

不是零,如果找到項目和成功移除,則為 0。

備註

如果 CObject 物件在別處,則不會刪除這可能會導致記憶體遺漏。

下表顯示類似 CMapStringToOb::RemoveKey的其他成員函式。

類別

成員函式

CMapPtrToPtr

BOOL RemoveKey( void* key);

CMapPtrToWord

BOOL RemoveKey( void* key);

CMapStringToPtr

BOOL RemoveKey( LPCTSTR key);

CMapStringToString

BOOL RemoveKey( LPCTSTR key);

CMapWordToOb

BOOL RemoveKey( WORD key);

CMapWordToPtr

BOOL RemoveKey( WORD key);

範例

針對所有集合範例的 CAge 類別的目錄參閱 CObList::CObList

CMapStringToOb map;

map.SetAt(_T("Bart"), new CAge(13));
map.SetAt(_T("Lisa"), new CAge(11));
map.SetAt(_T("Homer"), new CAge(36));
map.SetAt(_T("Marge"), new CAge(35));
map.RemoveKey(_T("Lisa")); // Memory leak: CAge object not
                           // deleted.
#ifdef _DEBUG
   afxDump.SetDepth(1);
   afxDump << _T("RemoveKey example: ") << &map << _T("\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

需求

Header: afxcoll.h

請參閱

參考

CMapStringToOb 類別

階層架構圖

CMapStringToOb::RemoveAll