リスト内の指定した位置の要素の直前に要素を追加します。
POSITION InsertBefore(
POSITION position,
CObject* newElement
);
パラメーター
[position]
直前の GetNext、GetPrev、Find メンバー関数の呼び出しで返された POSITION 値。newElement
このリストに追加するオブジェクト ポインター。
戻り値
反復処理やオブジェクト ポインターの取得のために使用する POSITION 値を返します。リストが空の場合は NULL を返します。
CObList::InsertBefore に類似している他のメンバー関数を以下に示します。
Class |
メンバー関数 |
---|---|
POSITION InsertBefore( POSITION position, void* newElement ); |
|
POSITION InsertBefore( POSITION position, const CString& newElement ); POSITION InsertBefore( POSITION position, LPCTSTR newElement ); |
使用例
CAge クラスのリストについては、「CObList::CObList」を参照してください。
CObList list;
POSITION pos1, pos2;
list.AddHead(new CAge(21));
list.AddHead(new CAge(40)); // List now contains (40, 21).
if ((pos1 = list.GetTailPosition()) != NULL)
{
pos2 = list.InsertBefore(pos1, new CAge(65));
}
#ifdef _DEBUG
afxDump.SetDepth(1);
afxDump << _T("InsertBefore example: ") << &list << _T("\n");
#endif
このプログラムの実行結果は次のようになります。
InsertBefore example: A CObList with 3 elements
a CAge at $4AE2 40
a CAge at $4B02 65
a CAge at $49E6 21
必要条件
**ヘッダー:**afxcoll.h