複製鏈接
請複製以下鏈接發送給好友

AddHead

鎖定
AddHead是添加一個新元素或列表元素到此開頭的列表,返回值第一個版本返回新插入。
外文名
AddHead
備    註
在操作之前該列表可為null。

AddHead函數原型

CList類中
POSITION AddHead(ARG_TYPE newElement );
void AddHead(CList* pNewList );
CObList類中
POSITION AddHead(CObject* newElement );
void AddHead(CObList* pNewList );

AddHead參數

CList類中
ARG_TYPE : 指定列表元素的類型模板參數(可以是引用)。
newElement: 新元素。
pNewList : 到另一 CList 的指針列表。 在 pNewList 的組件將添加到此列表。
CObList類中
newElement:要添加的 CObject 指向此列表。
pNewList :到另一 CObList 的指針列表。 在 pNewList 的組件將添加到此列表。

AddHead返回值

第一個版本返回新插入的元素的 POSITION 值。

AddHead其他信息

在操作之前該列表可為null。

AddHead示例

CList類中
// Declarations of the variables used in the example
CList<CString,CString&> myList;
CList<CString,CString&> myList2;
// There are two versions of CList::AddHead: one adds a single
// element to the front of the list, the second adds another list
// to the front.
// This adds the string "ABC" to the front of myList.
// myList is a list of CStrings (ie defined as CList<CString,CString&>).
myList.AddHead(CString(_T("ABC")));
// This adds the elements of myList2 to the front of myList.
myList.AddHead(&myList2);
CObList類
用於列表 CAge 選件類參見 CObList::CObList。
CObList list;
list.AddHead(new CAge(21)); // 21 is now at head.
list.AddHead(new CAge(40)); // 40 replaces 21 at head.
#ifdef _DEBUG
afxDump.SetDepth(1);
afxDump<<_T("AddHead example: ")<<&list<<_T("\n");
#endif [1-2] 
參考資料