Condividi tramite


CObArray::InsertAt

Inserire un elemento (o tutti gli elementi in un'altra matrice) a un indice specificato.

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

Parametri

  • nIndex
    Un intero che può essere maggiore del valore restituito da GetUpperBound.

  • newElement
    Il puntatore CObject da inserire in questa matrice.newElement di valore NULL è consentito.

  • nCount
    Il numero di volte questo elemento deve essere inserito (impostato su 1).

  • nStartIndex
    Un intero che può essere maggiore del valore restituito da GetUpperBound.

  • pNewArray
    Un'altra matrice contenente gli elementi da aggiungere a questa matrice.

Note

La prima versione InsertAt inserire un elemento (o più copie di un elemento a un indice specificato in una matrice.Nel processo, scorrere (incrementando l'indice) dell'elemento esistente a questo indice e scorre in tutti gli elementi su.

La seconda versione inserisce tutti gli elementi da un'altra raccolta CObArray, a partire dalla posizione nStartIndex.

La funzione SetAt, invece, sostituisce un elemento di matrice specificata e non scorrono elementi.

Nella tabella seguente vengono illustrate altre funzioni membro che sono simili a CObArray::InsertAt.

Classe

Funzione membro

CByteArray

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

    generare( CMemoryException* );

void InsertAt( INT_PTR nStartIndex, CByteArray* pNewArray);

    generare( CMemoryException* );

CDWordArray

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

    generare( CMemoryException* );

void InsertAt( INT_PTR nStartIndex, CDWordArray* pNewArray);

    generare( CMemoryException* );

CPtrArray

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

    generare( CMemoryException* );

void InsertAt( INT_PTR nStartIndex, CPtrArray* pNewArray);

    generare( CMemoryException* );

CStringArray

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

    generare( CMemoryException* );

void InsertAt( INT_PTR nStartIndex, CStringArray* pNewArray);

    generare( CMemoryException* );

CUIntArray

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

    generare( CMemoryException* );

void InsertAt( INT_PTR nStartIndex, CUIntArray* pNewArray);

    generare( CMemoryException* );

CWordArray

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

    generare( CMemoryException* );

void InsertAt( INT_PTR nStartIndex, CWordArray* pNewArray);

    generare( CMemoryException* );

Esempio

Vedere CObList::CObList per un elenco CAge utilizzata in tutti gli esempi di raccolta.

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      

I risultati di questo programma sono:

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

Requisiti

Header: afxcoll.h

Vedere anche

Riferimenti

Classe di CObArray

Grafico della gerarchia

CObArray::SetAt

CObArray::RemoveAt