CObArray::SetAtGrow
指定したインデックス位置に配列要素を格納します。
void SetAtGrow(
INT_PTR nIndex,
CObject* newElement
);
パラメーター
nIndex
0 以上の整数のインデックス。newElement
配列に追加するオブジェクト ポインター。 NULL 値も指定できます。
解説
必要に応じて、配列を自動的に拡張します (つまり、新しい要素を格納できるように上限が調整されます)。
CObArray::SetAtGrow に類似している他のメンバー関数を以下に示します。
Class |
メンバー関数 |
---|---|
void SetAtGrow( INT_PTR nIndex, BYTE newElement ); throw( CMemoryException* ); |
|
void SetAtGrow( INT_PTR nIndex, DWORD newElement ); throw( CMemoryException* ); |
|
void SetAtGrow( INT_PTR nIndex, void* newElement ); throw( CMemoryException* ); |
|
void SetAtGrow( INT_PTR nIndex, LPCTSTR newElement ); throw( CMemoryException* ); |
|
void SetAtGrow( INT_PTR nIndex, UINT newElement ); throw( CMemoryException* ); |
|
void SetAtGrow( INT_PTR nIndex, WORD newElement ); throw( CMemoryException* ); |
使用例
すべてのコレクションの例で使われている CAge クラスのリストについては、CObList::CObList を参照してください。
CObArray arr;
arr.Add(new CAge(21)); // Element 0
arr.Add(new CAge(40)); // Element 1
arr.SetAtGrow(3, new CAge(65)); // Element 2 deliberately
// skipped.
#ifdef _DEBUG
afxDump.SetDepth(1);
afxDump << _T("SetAtGrow example: ") << &arr << _T("\n");
#endif
このプログラムの実行結果は次のようになります。
SetAtGrow example: A CObArray with 4 elements
[0] = a CAge at $47C0 21
[1] = a CAge at $4800 40
[2] = NULL
[3] = a CAge at $4840 65
必要条件
**ヘッダー:**afxcoll.h