Can we use C++ type array in Symbain C++ ?

Login to reply to this topic.
Fri, 2008-02-22 14:07
Joined: 2006-12-19
Forum posts: 72

Hi ,

Can we deaclare an array of pointer to objcets like this in symbian:

int i=0;
anArray[i++]=AClass:NewLC();

where anArray is declared as :

AClass* anArray[10];


Fri, 2008-02-22 14:09
Joined: 2004-05-24
Forum posts: 981
Re: Can we use C++ type array in Symbain C++ ?

Of course you can.
The only think you have to keep in mind is memory management. In this case, what exactly will you put on CS (probably a TCleanupItem...)


pirosl

Wed, 2008-02-27 21:12
Joined: 2003-09-29
Forum posts: 32
Re: Can we use C++ type array in Symbain C++ ?

Instead of defining your own TCleanupItem, you might want to take a look at CleanupArrayDeletePushL function defined in e32base.h:

int* array = new(ELeave) int[10];
CleanupArrayDeletePushL(array);

// use array

CleanupStack::PopAndDestroy(); // calls delete [] array

Of course, for an array that is member of a C-class you have to explicitly call array deletion operator when deleting it.


Jari

Wed, 2008-02-27 22:01
Joined: 2007-09-23
Forum posts: 151
Re: Can we use C++ type array in Symbain C++ ?

What is the point in doing so when there are existing SYmbian arrays that are safer to use and will be compatible with the cleanup stack?

Wed, 2008-02-27 23:00
Joined: 2003-12-05
Forum posts: 607
Re: Can we use C++ type array in Symbain C++ ?

If you want the simplicity of plain fixed size arrays and the safety of the bounds checking arrays, use TFixedArray:

http://www.symbian.com/developer/techlib/v70sdocs/doc_source/reference/cpp/FixedSizeArrays/TFixedArrayClass.html
http://www.symbian.com/developer/techlib/v70sdocs/doc_source/reference/cpp/FixedSizeArrays/UsingTFixedArray.guide.html

However, if you have an unknown or large number of array elements or need dynamic arrays, do as Numpty Alert suggests - use the dynamic arrays.

  • Login to reply to this topic.