creating array of objects ??

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

Hi,

to create an array of 2 objects (e.g. of type '__gc class Airplane') I need
to do :

Airplane * arrAirplanes __gc[] = new Airplane* __gc[2];
arrAirplanes[0] = new Airplane("N12344");
arrAirplanes[1] = new Airplane("N12345");

Actually, I create an array of Airplane-pointers first and then create the
objects afterwards.

Now, what I would like is create the objects immediately, when creating the
array, something I can do in unmanaged C++ :
MyClass *p= new MyClass[2];

here are the objects created immediately.

Unfortunately, this does not work when the class is declared with __gc.
Or is it possible anyhow ?

In short, how do I create an array of managed objects directly, instead of
having to create an array of pointers first and then make the pointers point
to valid objects.

Thanks
Chris
 
Fri. Aug. 27, 2004 6:20 PM PT

I have created few macros as Managed C++ array syntax is very, very weird.
Try this.....

#define MRArrayT(__T,__V) __T *__V[]

MRArrayT(MyObject, arrObj) = { new MyObject(), new MyObject() };

In the { } braces you create as many objects you want, and it creates the
arrObj, as an arrays.

Good Luck.
 
Chris said:
Hi,

to create an array of 2 objects (e.g. of type '__gc class Airplane') I need
to do :

Airplane * arrAirplanes __gc[] = new Airplane* __gc[2];
arrAirplanes[0] = new Airplane("N12344");
arrAirplanes[1] = new Airplane("N12345");

Actually, I create an array of Airplane-pointers first and then create the
objects afterwards.

Now, what I would like is create the objects immediately, when creating the
array, something I can do in unmanaged C++ :
MyClass *p= new MyClass[2];

here are the objects created immediately.

Unfortunately, this does not work when the class is declared with __gc.
Or is it possible anyhow ?

In short, how do I create an array of managed objects directly, instead of
having to create an array of pointers first and then make the pointers point
to valid objects.

You can do this with value types.
 
Back
Top