Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

[Index] [Glossary] [Previous] [Next]



Location: e32std.h
Link against:

Class TArray

template <class T>
    class TArray

Support

Supported from 5.0

Description

Generic array.

This class defines a generic array which can be constructed by any of the templated concrete arrays.

An instance of this class can be constructed by any of the templated array classes:

and also the template specialisation classes:

It allows a degree of polymorphism amongst the array classes. It permits the operator[]and the Count() member functions of an array to be invoked without knowing which array class has been used to construct that array.

TArray allows access to elements of an array but does not permit changes to those elements.

Use the Array() member function of an array to construct and return a TArray<class T> object for that array.

A TArray<class T> type object is not intended to be constructed explicitly by user code.

Note that in ER5, this class was defined in e32base.h

Derivation

TArrayGeneric array

Defined in TArray:
Count(), TArray(), operator[]


Construction


TArray()

TArray(TInt (*aCount)(const CBase *aPtr),const TAny* (*anAt)(const CBase* aPtr,TInt anIndex),const CBase* aPtr));

Description

The constructor for a TArray object.

A TArray object is not intended to be instantiated explicitly. An object of this type is instantiated as a result of a call to to the Array() member function of a concrete array class, specifically:

Parameters

TInt (*aCount)(const CBase *aPtr)

A pointer to a function which takes a const CBase* argument and returns a TInt. aCount must point to the member function which returns the current number of elements of type <class T> contained in the array at aPtr, for which this TArray is being constructed. This argument is supplied by the Array() member function of the array class.

const TAny* (*anAt)(const CBase* aPtr, TInt anIndex)

A pointer to a function which takes a const CBase* and a TInt argument and returns a pointer to TAny. anAt must point to the member function which returns a reference to the element located at position anIndex within the array at aPtr, for which this TArray is being constructed. This argument is supplied by the Array() member function of the array class.

const CBase* aPtr

A pointer to the array for which this TArray is being constructed. This argument is supplied by the Array() member function of the array class.

[Top]


Basic information


Count()

TInt Count() const;

Description

Returns the number of elements currently held in the array for which this generic array has been constructed.

Return value

TInt

The number of array elements

[Top]


Indexing into the array


operator[]

const T& operator[](TInt anIndex) const;

Description

Returns a reference to the element located at the specified position.

The returned reference is const and cannot be used to change the element. Any member function of the referenced template class T must be declared as const if that function is to be accessed through this operator.

Parameters

TInt anIndex

The position of the element of type <class T> within the array for which this TArray has been constructed. The position is relative to zero; i.e. zero implies the first element in the array. This value must be non-negative and less than the number of objects currently within the array otherwise the operation raise an E32USER-CBase 21 panic.

Return value

const T&

A const reference to the element of type <class T> located at position anIndex within the array for which this TArray has been constructed.