Condividi tramite


CObArray::SetAt

Imposta un elemento matrice all'indice specificato.

void SetAt(
   INT_PTR nIndex,
   CObject* newElement 
);

Parametri

  • nIndex
    Un intero maggiore o uguale a 0 e minore o uguale al valore restituito da GetUpperBound.

  • newElement
    Il puntatore all'oggetto da inserire nella matrice.Un valore null è consentito.

Note

SetAt non comporta la matrice di sviluppo di.Utilizzare SetAtGrow se si desidera che la matrice per sviluppare automaticamente.

È necessario verificare che il valore di indice rappresenta un percorso valido nella matrice.Se è fuori dai limiti, la versione di debug delle asserzioni di libreria.

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

Classe

Funzione membro

CByteArray

void SetAt( INT_PTRnIndex, BYTE newElement);

CDWordArray

void SetAt( INT_PTRnIndex, DWORD newElement);

CPtrArray

void SetAt( INT_PTRnIndex, void* newElement);

CStringArray

void SetAt( INT_PTRnIndex, LPCTSTR newElement);

CUIntArray

void SetAt( INT_PTRnIndex, UINT newElement);

CWordArray

void SetAt( INT_PTRnIndex, WORD newElement);

Esempio

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

CObArray arr;
CObject* pa;

arr.Add(new CAge(21)); // Element 0
arr.Add(new CAge(40)); // Element 1
if ((pa = arr.GetAt(0)) != NULL)
{
   arr.SetAt(0, new CAge(30));  // Replace element 0.
   delete pa; // Delete the original element at 0.
}
#ifdef _DEBUG
   afxDump.SetDepth(1);
   afxDump << _T("SetAt example: ") << &arr << _T("\n");
#endif      

I risultati di questo programma sono:

SetAt example: A CObArray with 2 elements

[0] = a CAge at $47E0 30

[1] = a CAge at $47A0 40

Requisiti

Header: afxcoll.h

Vedere anche

Riferimenti

Classe di CObArray

Grafico della gerarchia

CObArray::GetAt

CObArray::SetAtGrow

CObArray::ElementAt

CObArray::operator [ ]