Symbian platform provides range checking for arrays.
Instead of declaring a C++ array directly:
TTest array[4];
use:
TFixedArray<TTest,4> array;
The array can be initialised either at construction time or by using the Copy() member function after construction.
... const TTest data[] = {TTest(1),TTest(2),TTest(3),TTest(4)}; ... // initialise at construction time TFixedArray<TTest,4> array(&data[0],4); ... // or later using Copy() TFixedArray<TTest,4> array; array.Copy(&data[0],4); ...
Accesses can be checked for legality using the At() function or the operator[] .
The At() function checks for a legal access in both a release build and a debug build while the operator[] only checks for a legal access in a debug build.
Assuming that the TTest class has a public member function called SetValue() , then a call to this function on the second element of the array is legal:
array.At(1).SetValue(100);
but an attempt to call this function on the fifth element raises a panic; in this example, there are only four elements:
array.At(5).SetValue(100); // panics
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.