CObArray::InsertAt

Insere elemento (ou todos os elementos em outros matriz) em um índice especificado.

void InsertAt(
   INT_PTR nIndex,
   CObject* newElement,
   INT_PTR nCount = 1 
);
void InsertAt(
   INT_PTR nStartIndex,
   CObArray* pNewArray 
);

Parâmetros

  • nIndex
    Um índice inteiro que pode ser maior que o valor retornado por GetUpperBound.

  • newElement
    O ponteiro de CObject a ser colocado em esta matriz.newElement de valor NULO é permitido.

  • nCount
    O número de vezes que esse elemento deve ser inserido (o padrão é 1).

  • nStartIndex
    Um índice inteiro que pode ser maior que o valor retornado por GetUpperBound.

  • pNewArray
    Outra matriz que contém os elementos a serem adicionados à matriz.

Comentários

A primeira versão de InsertAt insere um elemento (ou várias cópias de um elemento) em um índice especificado em uma matriz.Em o processo, desloca anterior (incremento) do índice elemento existente no índice, e desloca acima de todos os elementos acima.

A segunda versão inserir todos os elementos de outra coleção de CObArray , começando na posição de nStartIndex .

A função de SetAt , por outro lado, substitui um elemento de matriz especificado e não muda quaisquer elementos.

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

Classe

Função de membro

CByteArray

void InsertAt( INT_PTR nIndex, BYTE newElement, int nCount=1 );

    throw( CMemoryException* );

void InsertAt( INT_PTR nStartIndex, CByteArray* pNewArray );

    throw( CMemoryException* );

CDWordArray

void InsertAt( INT_PTR nIndex, DWORD newElement, int nCount=1 );

    throw( CMemoryException* );

void InsertAt( INT_PTR nStartIndex, CDWordArray* pNewArray );

    throw( CMemoryException* );

CPtrArray

void InsertAt( INT_PTR nIndex, void* newElement, int nCount=1 );

    throw( CMemoryException* );

void InsertAt( INT_PTR nStartIndex, CPtrArray* pNewArray );

    throw( CMemoryException* );

CStringArray

void InsertAt( INT_PTR nIndex, LPCTSTR newElement, int nCount=1 );

    throw( CMemoryException* );

void InsertAt( INT_PTR nStartIndex, CStringArray* pNewArray );

    throw( CMemoryException* );

CUIntArray

void InsertAt( INT_PTR nIndex, UINT newElement, int nCount=1 );

    throw( CMemoryException* );

void InsertAt( INT_PTR nStartIndex, CUIntArray* pNewArray );

    throw( CMemoryException* );

CWordArray

void InsertAt( INT_PTR nIndex, WORD newElement, int nCount=1 );

    throw( CMemoryException* );

void InsertAt( INT_PTR nStartIndex, CWordArray* pNewArray );

    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 (will become 2).
arr.InsertAt(1, new CAge(30));  // New element 1
#ifdef _DEBUG
   afxDump.SetDepth(1);
   afxDump << _T("InsertAt example: ") << &arr << _T("\n");
#endif      

Os resultados do programa é a seguinte:

InsertAt example: A CObArray with 3 elements

[0] = a CAge at $45C8 21

[1] = a CAge at $4646 30

[2] = a CAge at $4606 40

Requisitos

Cabeçalho: afxcoll.h

Consulte também

Referência

Classe de CObArray

Gráfico de hierarquia

CObArray::SetAt

CObArray::RemoveAt