CObArray::Add

Adiciona um novo elemento ao final de uma matriz, crescendo a matriz por 1.

INT_PTR Add(
   CObject* newElement 
);

Parâmetros

  • newElement
    O ponteiro de CObject a ser adicionado a essa matriz.

Valor de retorno

O índice de um elemento adicionado.

Comentários

Se SetSize foi usado com um valor de nGrowBy maior que 1, então a memória adicional pode ser atribuído.Em o entanto, o limite superior aumentará somente por 1.

A tabela a seguir mostra outras funções de membro que são semelhantes a CObArray::Add.

Classe

Função de membro

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* );

Exemplo

Consulte CObList::CObList para uma listagem da classe de CAge usada em todos os exemplos de coleção.

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      

Os resultados do programa é a seguinte:

Add example: A CObArray with 2 elements

[0] = a CAge at $442A 21

[1] = a CAge at $4468 40

Requisitos

Cabeçalho: afxcoll.h

Consulte também

Referência

Classe de CObArray

Gráfico de hierarquia

CObArray::SetAt

CObArray::SetAtGrow

CObArray::InsertAt

CObArray::operator [ ]