2.2.7.1.3 Array::GetAt

Description

Provides access to an element in the array

Syntax

_TemplType GetAt( int nIndex )const

Parameters

nIndex
[input] The array index which is queried for the element

Return

Returns a reference to the object at the requested index

Examples

EX1

#include <Array.h>
struct PERSON
{
	int nID;
};
void Array_GetAt_ex1()
{
	Array<PERSON&> arp(true);
	int nTotal = 5;
	for ( int ii = 0; ii < nTotal; ii++ )
	{
		PERSON* pp = new PERSON;
		//assume memory allocated successfully.
		pp->nID = ii + 1;
		arp.Add(*pp);
	}
	//get the middle item to change its value.
	int nMid = nTotal/2;
	if ( nMid < nTotal )
	{
		PERSON& pm = arp.GetAt(nMid);
		pm.nID = 12345;
	}
	for ( ii = 0; ii < nTotal; ii++ )
		printf("Person %d's ID is : %d\n", ii + 1, arp.GetAt(ii).nID);
		
}

Remark

See Also

Array::SetAt

Header to Include

Array.h