网站首页  词典首页

请输入您要查询的计算机术语:

 

术语 CObList::SetAt
释义 CObList::SetAt

void SetAt( POSITION pos, CObject* newElement );

参数:
pos元素所要设定的POSITION值。
newElement要写入列表的CObject指针。

说明:
一个类型为 POSITION 的变量是列表的一个键值。不同于索引的是, 不能对POSITION 值执行操作。 SetAt 将把给定的CObject 指针写到列表中的指定位置。
必须确保所给的POSITION值指向列表中的一个有效位置。否则,MFC库(Microsoft Foundation Class Library)的调试版本将就此给出警告声明。

示例:
CObList list;
CObject* pa;
POSITION pos;

list.AddHead( new CAge( 21 ) );
list.AddHead( new CAge( 40 ) ); // List now contains (40, 21).
if( ( pos = list.GetTailPosition()) != NULL )
{
  pa = list.GetAt( pos ); // Save the old pointer for deletion.
  list.SetAt( pos, new CAge( 65 ) ); // Replace the tail element.
  delete pa; // Deletion avoids memory leak.
}
#ifdef _DEBUG
   afxDump.SetDepth( 1 );
   afxDump << "SetAt example: " << &list << "\";
#endif

该程序的结果如下:
SetAt example: A CObList with 2 elements
a CAge at $4D98 40
a CAge at $4DB8 65

请参阅:
CObList::Find, CObList::GetAt, CObList::GetNext, CObList::GetPrev
随便看

 

MFC类库中文详解手册包含4274条MFC类库参考词条,基本涵盖了Microsoft基本类库中的类、全局函数、全局变量和宏的内容,是计算机编程的有利工具。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 12:34:44