Condividi tramite


CMapStringToOb::Lookup

Returns a CObject pointer based on a CString value.

BOOL Lookup(
   LPCTSTR key,
   CObject*& rValue 
) const;

Parameters

  • key
    Specifies the string key that identifies the element to be looked up.

  • rValue
    Specifies the returned value from the looked-up element.

Return Value

Nonzero if the element was found; otherwise 0.

Remarks

Lookup uses a hashing algorithm to quickly find the map element with a key that matches exactly (CString value).

The following table shows other member functions that are similar to CMapStringToOb::LookUp.

Class

Member Function

CMapPtrToPtr

BOOL Lookup( void* key, void*& rValue ) const;

CMapPtrToWord

BOOL Lookup( void* key, WORD& rValue ) const;

CMapStringToPtr

BOOL Lookup( LPCTSTR key, void*& rValue ) const;

CMapStringToString

BOOL Lookup( LPCTSTR key, CString& rValue ) const;

CMapWordToOb

BOOL Lookup( WORD key, CObject*& rValue ) const;

CMapWordToPtr

BOOL Lookup( WORD key, void*& rValue ) const;

Example

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

CMapStringToOb map;
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));
ASSERT(map.Lookup(_T("Lisa"), (CObject*&)pa)); // Is "Lisa" in the map?
ASSERT(*pa ==  CAge(11)); // Is she 11?         

Requirements

Header: afxcoll.h

See Also

Reference

CMapStringToOb Class

Hierarchy Chart

CMapStringToOb::operator [ ]

Other Resources

CMapStringToOb Members