Udostępnij za pośrednictwem


CObArray::Add

Adds a new element to the end of an array, growing the array by 1.

INT_PTR Add(
   CObject* newElement 
);

Parameters

  • newElement
    The CObject pointer to be added to this array.

Return Value

The index of the added element.

Remarks

If SetSize has been used with an nGrowBy value greater than 1, then extra memory may be allocated. However, the upper bound will increase by only 1.

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

Class

Member Function

CByteArray

INT_PTR Add( BYTE newElement );

    throw( CMemoryException* );

CDWordArray

INT_PTR Add( DWORD newElement );

    throw( CMemoryException* );

CPtrArray

INT_PTR Add( void* newElement );

    throw( CMemoryException* );

CStringArray

INT_PTR Add( LPCTSTR newElement );     throw( CMemoryException* );

INT_PTR Add(const CString& newElement);

CUIntArray

INT_PTR Add( UINT newElement );

    throw( CMemoryException* );

CWordArray

INT_PTR Add( 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
#ifdef _DEBUG
   afxDump.SetDepth(1);
   afxDump << _T("Add example: ") << &arr << _T("\n");
#endif      

The results from this program are as follows:

Add example: A CObArray with 2 elements

[0] = a CAge at $442A 21

[1] = a CAge at $4468 40

Requirements

Header: afxcoll.h

See Also

Reference

CObArray Class

Hierarchy Chart

CObArray::SetAt

CObArray::SetAtGrow

CObArray::InsertAt

CObArray::operator [ ]

Other Resources

CObArray Members