CMapStringToOb::GetNextAssoc

void GetNextAssoc( POSITION& rNextPosition, CString& rKey, CObject*& rValue ) const;

Parameters

rNextPosition

Specifies a reference to a POSITION value returned by a previous GetNextAssoc or GetStartPosition call.

rKey

Specifies the returned key of the retrieved element (a string).

rValue

Specifies the returned value of the retrieved element (a CObject pointer). See Remarks for more about this parameter.

Remarks

Retrieves the map element at rNextPosition, then updates rNextPosition to refer to the next element in the map. This function is most useful for iterating through all the elements in the map. Note that the position sequence is not necessarily the same as the key value sequence.

If the retrieved element is the last in the map, then the new value of rNextPosition is set to NULL.

For the rValue parameter, be sure to cast your object type to CObject*&, which is what the compiler requires, as shown in the following example:

CMyObject* ob;
map.GetNextAssoc(pos, key, (CObject*&)ob);

This is not true of GetNextAssoc for maps based on templates.

Example

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

// example for CMapStringToOb::GetNextAssoc and CMapStringToOb::GetStartPosition
   CMapStringToOb map;
   POSITION pos;
   CString key;
   CAge* pa;
   
   map.SetAt( "Bart", new CAge( 13 ) );
   map.SetAt( "Lisa", new CAge( 11 ) );
   map.SetAt( "Homer", new CAge( 36 ) );
   map.SetAt( "Marge", new CAge( 35 ) );
   // Iterate through the entire map, dumping both name and age.
   for( pos = map.GetStartPosition(); pos != NULL; )
   {
   map.GetNextAssoc( pos, key, (CObject*&)pa );
#ifdef _DEBUG
      afxDump << key << " : " << pa << "\n";
#endif
   }

The results from this program are as follows:

Lisa : a CAge at $4724 11
Marge : a CAge at $47A8 35
Homer : a CAge at $4766 36
Bart : a CAge at $45D4 13

CMapStringToOb OverviewClass MembersHierarchy Chart

See Also   CMapStringToOb::GetStartPosition