示例:
请参阅CObList::CObList,了解所有收集示例中使用的CAge类。
//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
}
该程序的运行结果如下:
Lisa : a CAge at $4724 11
Marge : a CAge at $47A8 35
Homer : a CAge at $4766 36
Bart : a CAge at $45D4 13