Share via


CMapStringToOb::RemoveKey

Looks up the map entry corresponding to the supplied key; then, if the key is found, removes the entry.

BOOL RemoveKey( 
   LPCTSTR key  
);

Parameters

  • key
    Specifies the string used for map lookup.

Return Value

Nonzero if the entry was found and successfully removed; otherwise 0.

Remarks

This can cause memory leaks if the CObject object is not deleted elsewhere.

The following table shows other member functions that are similar to CMapStringToOb::RemoveKey.

Class

Member Function

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 );

Example

See CObList::CObList for a listing of the CAge class used in all collection examples.

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         

The results from this program are as follows:

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

Requirements

Header: afxcoll.h

See Also

Reference

CMapStringToOb Class

Hierarchy Chart

CMapStringToOb::RemoveAll

Other Resources

CMapStringToOb Members