术语 | CMapStringToOb::SetAt | ||||
释义 | CMapStringToOb::SetAt void SetAt( LPCTSTR key, CObject* newValue ); throw( CMemoryException ); 参数:
说明: 主要用途是在映射中插入一个元素。首先,查找关键码,如果发现了该关键码,然后改变对应的值;否则,将创建新的关键码值元素。 示例: 请参阅CObList::CObList,了解所有收集示例中使用的CAge类。 //example for CMapStringToOb::SetAt CMapStringToOb map; CAge* pa; map.SetAt( "Bart", new CAge( 13 ) ); map.SetAt( "Lisa", new CAge( 11 ) ); // Map contains 2 elements. #ifdef _DEBUG afxDump.SetDepth( 1 ); afxDump << "before Lisa's birthday: " << &map << "\"; #endif if( map.Lookup( "Lisa", (CObject *&)pa ) ) { // CAge 12 pointer replaces CAge 11 pointer. map.SetAt( "Lisa", new CAge( 12 ) ); delete pa; // Must delete CAge 11 to avoid memory leak. } #ifdef _DEBUG afxDump << "after Lisa's birthday: " << &map << "\"; #endif 该程序的结果如下: before Lisa's birthday: A CMapStringToOb with 2 elements [Lisa] = a CAge at $493C 11 [Bart] = a CAge at $4654 13 after Lisa's birthday: A CMapStringToOb with 2 elements [Lisa] = a CAge at $49C0 12 [Bart] = a CAge at $4654 13 请参阅:CMapStringToOb::Lookup, CMapStringToOb::operator [] |
||||
随便看 |
|
MFC类库中文详解手册包含4274条MFC类库参考词条,基本涵盖了Microsoft基本类库中的类、全局函数、全局变量和宏的内容,是计算机编程的有利工具。