Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

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



How to remove elements

Elements can be removed from an array.

The following code fragment shows the deletion of the second TElement object from a CArrayFixFlat<class T> array:

class TElement
 {
public :
 TElement();
public :
 TBuf<4> iData;
 };

CArrayFixFlat<TElement>* fixflat;
fixflat = new (ELeave) CArrayFixFlat<TElement>(3);
...
... // elements added to the array at some point
...
fixflat->Delete(1);

To delete what are now the third and fourth elements from the array, i.e. the two contiguous elements starting at position two, use Delete() and specify both the starting position and the number of elements:

fixflat->Delete(2,2);


Notes

fixflat->Compress();

TInt index;
CElement* ptr;
...
index = ptrflat->Count();
...
ptr = (*ptrflat)[--index];
ptrflat->Delete(index);
delete ptr;
...
ptr = ptrflat->At(--index);
ptrflat->Delete(index);
delete ptr;