Share via


CObArray::InsertAt

Inserta un elemento (o todos los elementos en otra matriz) en el índice especificado.

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

Parámetros

  • nIndex
    un índice entero que puede ser mayor que el valor devuelto por GetUpperBound.

  • newElement
    El puntero de CObject se coloque en esta matriz.newElement de valor NULL está permitido.

  • nCount
    El número de veces que este elemento debe insertarse (el valor predeterminado de 1).

  • nStartIndex
    un índice entero que puede ser mayor que el valor devuelto por GetUpperBound.

  • pNewArray
    Otra matriz que contiene los elementos que se van a esta matriz.

Comentarios

La primera versión de InsertAt inserta un elemento (o varias copias de un elemento) en un índice especificado en una matriz.En el proceso, se desplaza hacia arriba (aumentando el índice) del elemento existente en este índice, y se desplaza sobre todos los elementos sobre ella.

La segunda versión inserta todos los elementos de otra colección de CObArray , desde la posición de nStartIndex .

La función de SetAt , en cambio, reemplazar un elemento de matriz especificado y no se mueve ningún elemento.

La tabla siguiente se muestran otras funciones miembro que son similares a CObArray::InsertAt.

Clase

Función miembro

CByteArray

InsertAt vacío (INT_PTR nIndex, BYTE newElement, int nCount = 1);

    throw (CMemoryException*);

InsertAt vacío (INT_PTR nStartIndex, CByteArray* pNewArray);

    throw (CMemoryException*);

CDWordArray

InsertAt vacío (INT_PTR nIndex, DWORD newElement, int nCount = 1);

    throw (CMemoryException*);

InsertAt vacío (INT_PTR nStartIndex, CDWordArray* pNewArray);

    throw (CMemoryException*);

CPtrArray

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

    throw (CMemoryException*);

InsertAt vacío (INT_PTR nStartIndex, CPtrArray* pNewArray);

    throw (CMemoryException*);

CStringArray

InsertAt vacío (INT_PTR nIndex, LPCTSTR newElement, int nCount = 1);

    throw (CMemoryException*);

InsertAt vacío (INT_PTR nStartIndex, CStringArray* pNewArray);

    throw (CMemoryException*);

CUIntArray

InsertAt vacío (INT_PTR nIndex, UINT newElement, int nCount = 1);

    throw (CMemoryException*);

InsertAt vacío (INT_PTR nStartIndex, CUIntArray* pNewArray);

    throw (CMemoryException*);

CWordArray

InsertAt vacío (INT_PTR nIndex, WORD newElement, int nCount = 1);

    throw (CMemoryException*);

InsertAt vacío (INT_PTR nStartIndex, CWordArray* pNewArray);

    throw (CMemoryException*);

Ejemplo

Vea CObList:: CObList para una lista de la clase de CAge utilizada en todos los ejemplos de la colección.

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      

Los resultados de este programa son los siguientes:

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

encabezado: afxcoll.h

Vea también

Referencia

Clase de CObArray

Gráfico de jerarquía

CObArray::SetAt

CObArray::RemoveAt