CMapStringToOb::operator [ ]

CObject*& operator [ ]( LPCTSTR key );

Return Value

A reference to a pointer to a CObject object; or NULL if the map is empty or key is out of range.

Remarks

This operator is a convenient substitute for the SetAt member function. Thus it can be used only on the left side of an assignment statement (an l-value). If there is no map element with the specified key, then a new element is created.

There is no “right side” (r-value) equivalent to this operator because there is a possibility that a key may not be found in the map. Use the Lookup member function for element retrieval.

Example

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

// example for CMapStringToOb::operator[]
   CMapStringToOb map;
   
   map["Bart"] = new CAge( 13 );
   map["Lisa"] = new CAge( 11 );
#ifdef _DEBUG
   afxDump.SetDepth( 1 );
   afxDump << "Operator [] example: " << &map << "\n";
#endif

The results from this program are as follows:

Operator [] example: A CMapStringToOb with 2 elements
    [Lisa] = a CAge at $4A02 11
    [Bart] = a CAge at $497E 13

CMapStringToOb OverviewClass MembersHierarchy Chart

See Also   CMapStringToOb::SetAt, CMapStringToOb::Lookup