CObArray::SetAtGrow

Sets the array element at the specified index.

void SetAtGrow(
   INT_PTR nIndex,
   CObject* newElement 
);

Parameters

  • nIndex
    An integer index that is greater than or equal to 0.

  • newElement
    The object pointer to be added to this array. A NULL value is allowed.

Remarks

The array grows automatically if necessary (that is, the upper bound is adjusted to accommodate the new element).

The following table shows other member functions that are similar to CObArray::SetAtGrow.

Class

Member Function

CByteArray

void SetAtGrow( INT_PTR nIndex, BYTE newElement );

    throw( CMemoryException* );

CDWordArray

void SetAtGrow( INT_PTR nIndex, DWORD newElement );

    throw( CMemoryException* );

CPtrArray

void SetAtGrow( INT_PTR nIndex, void* newElement );

    throw( CMemoryException* );

CStringArray

void SetAtGrow( INT_PTR nIndex, LPCTSTR newElement );

    throw( CMemoryException* );

CUIntArray

void SetAtGrow( INT_PTR nIndex, UINT newElement );

    throw( CMemoryException* );

CWordArray

void SetAtGrow( INT_PTR nIndex, WORD newElement );

    throw( CMemoryException* );

Example

See CObList::CObList for a listing of the CAge class used in all collection examples.

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      

The results from this program are as follows:

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

Requirements

Header: afxcoll.h

See Also

Reference

CObArray Class

Hierarchy Chart

CObArray::GetAt

CObArray::SetAt

CObArray::ElementAt

CObArray::operator [ ]

Other Resources

CObArray Members