CMapStringToOb::RemoveKey

BOOL RemoveKey( LPCTSTR key );

Return Value

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

Parameters

key

Specifies the string used for map lookup.

Remarks

Looks up the map entry corresponding to the supplied key; then, if the key is found, removes the entry. This can cause memory leaks if the CObject object is not deleted elsewhere.

Example

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

// 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

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

CMapStringToOb OverviewClass MembersHierarchy Chart

See Also   CMapStringToOb::RemoveAll