Share via


CMapStringToOb::GetNextAssoc

擷取對應項目在 rNextPosition,然後更新 rNextPosition 參考對應中的下一個項目。

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

參數

  • rNextPosition
    指定與前一個 GetNextAssocGetStartPosition 呼叫傳回的 位置 值的參考。

  • rKey
    指定所擷取的項目 (字串) 的傳回的索引鍵。

  • rValue
    指定所擷取的項目 ( CObject 指標) 所傳回的值。 如需更多。請參閱<備註>有關這個參數。

備註

這個函式會逐一查看最有用通過所有項目位於對應。 請注意位置順序不一定會與索引鍵值序列。

如果所擷取的項目是在對應中的最後一個,則 rNextPosition 的 新值設定為 NULL

如需 rValue 參數,請確定轉型為您的物件型別加入 CObject*_&,可供編譯器要求,,如下列範例所示:

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

這不是可靠 GetNextAssoc 對於以該範本為基礎的對應。

下表顯示類似 CMapStringToOb::GetNextAssoc的其他成員函式。

類別

成員函式

CMapPtrToPtr

void GetNextAssoc( POSITION_& rNextPosition, void*_& rKey, void*_& rValue ) const;

CMapPtrToWord

void GetNextAssoc( POSITION_& rNextPosition, void*_& rKey, WORD_& rValue ) const;

CMapStringToPtr

void GetNextAssoc( POSITION_& rNextPosition, CString_& rKey, void*_& rValue ) const;

CMapStringToString

void GetNextAssoc( POSITION_& rNextPosition, CString_& rKey, CString_& rValue ) const;

CMapWordToOb

void GetNextAssoc( POSITION_& rNextPosition, WORD_& rKey, CObject*_& rValue ) const;

CMapWordToPtr

void GetNextAssoc( POSITION_& rNextPosition, WORD_& rKey, void*_& rValue ) const;

範例

針對所有集合範例的 CAge 類別的目錄參閱 CObList::CObList

CMapStringToOb map;
POSITION pos;
CString key;
CAge* pa;

map.SetAt(_T("Bart"), new CAge(13));
map.SetAt(_T("Lisa"), new CAge(11));
map.SetAt(_T("Homer"), new CAge(36));
map.SetAt(_T("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 << _T(" : ") << pa << _T("\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

需求

Header: afxcoll.h

請參閱

參考

CMapStringToOb 類別

階層架構圖

CMapStringToOb::GetStartPosition