CMapStringToOb::operator []

Syntax

CObject*& operator []( const char* key );

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

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

See Also

CMapStringToOb::SetAt, CMapStringToOb::Lookup