Click to See Complete Forum and Search --> : Array of class objects as data member to another class


bloodsample
January 6th, 2007, 08:53 PM
Hi,

Can someone tell me the correct way of doing this: I want to have a class contain an array of objects of some other class as one of its non-static data members.

As simple example let's say we have a class CPerson which contains an array of object of type CPet. So every person has an unspecified number of pets (ie the array size should be dynamic and increase as a person adds more pets).

What do I have to write in the header file (declaration) of the CPerson class? Also how do I initialize in the cpp file of the same class?

I'm confused with the C++/CLI notation for an array.

What I've tried now is to declare as:
CPet^ petarray;

And then initialize as:
petarray = gcnew array<CPet>();

This doesn't work and is just some stuff I picked up on some website.

Can someone please explain array declaration syntax for C++/CLI and how I can declare an array of class objects (with preferable dynamic size, but not crucial).

Thanks in advance

bloodsample
January 6th, 2007, 09:06 PM
nm, I figured it out.

nagira
November 22nd, 2007, 01:09 AM
hai,

I have faced the same problem.

can you help me to fix this.

it will b emore helpful if you tell how you fix this

Thank you

Regards,
Nagira