By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,900 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,900 IT Pros & Developers. It's quick & easy.

creating array of objects ??

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

"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

P: n/a

"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.