473,387 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 1898
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: gonzalo briceno | last post by:
I have been using phplib for a while and I really like the framework except for form creation. Maybe it is me but I in my opinion there isn't a good way to create forms or should I say, everything...
4
by: Faheem Mitha | last post by:
Dear People, I have the current modest goal. Given a user defined class, I want to creata an array of instances of that class. Consider the following class. class cell: def...
8
by: cody | last post by:
i basically want to create an object which contains an array (the last element of the class). the size of the array is determined when the object is created. for performance reasons (avoiding...
5
by: Keiron Waites | last post by:
<script language="JavaScript" type="text/javascript"> <!-- var array1 = new Array(); var array1i = new Array(); array1 = array1i; alert(array1); // --> </script>
20
by: svend | last post by:
I'm messing with some code here... Lets say I have this array: a1 = ; And I apply slice(0) on it, to create a copy: a2 = a1.slice(0); But this isn't a true copy. If I go a1 = 42, and then...
1
by: Chris | last post by:
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; arrAirplanes = new Airplane("N12344"); arrAirplanes...
31
by: JoeC | last post by:
I have read books and have ideas on how to create objects. I often create my own projects and programs. They end up getting pretty complex and long. I often use objects in my programs they are...
3
by: Bartholomew Simpson | last post by:
I am writing some C++ wrappers around some legacy C ones - more specifically, I am providing ctors, dtors and assignment operators for the C structs. I have a ton of existing C code that uses...
6
sammyboy78
by: sammyboy78 | last post by:
I'm trying to display my array of objects in a GUI. How do I get JLabel to refer to the data in my objects? I've read my textbook and some tutorials online I just cannot get this. Plus all the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.