469,934 Members | 1,844 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,934 developers. It's quick & easy.

creating array of objects ??

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

Nov 17 '05 #1
5 1734
Chris wrote:
Unfortunately, this does not work when the class is declared with
__gc. Or is it possible anyhow ?


No.

--
Greetings
Jochen
Nov 17 '05 #2
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" <ch********@pandora.be> wrote in message
news:Mz**********************@phobos.telenet-ops.be...
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

Nov 17 '05 #3
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" <ch********@pandora.be> wrote in message
news:Mz**********************@phobos.telenet-ops.be...
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

Nov 17 '05 #4

"Chris" <ch********@pandora.be> wrote in message
news:Mz**********************@phobos.telenet-ops.be...
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.
--
Vladimir Nesterovsky
e-mail: vl******@nesterovsky-bros.com
home: www.nesterovsky-bros.com
Nov 17 '05 #5

"Chris" <ch********@pandora.be> wrote in message
news:Mz**********************@phobos.telenet-ops.be...
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.
--
Vladimir Nesterovsky
e-mail: vl******@nesterovsky-bros.com
home: www.nesterovsky-bros.com
Nov 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Faheem Mitha | last post: by
1 post views Thread by Chris | last post: by
31 posts views Thread by JoeC | last post: by
3 posts views Thread by Bartholomew Simpson | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.