Archived

This topic is now archived and is closed to further replies.

xiros

array of a class of a class

Recommended Posts

I need to have a class for my data and then within that class have another class as an array. How would I define the second class as an array and how can I change the size of the array within the program? example: class1.class2[50].var1 Thanks for any help.

Share this post


Link to post
Share on other sites
quote:
I need to have a class for my data and then within that class have another class as an array.

Then declare an array as a member variable of your first class.

quote:
How would I define the second class as an array

See above, or overload Class2::operator[] so that you can use array-access syntax to do ... something with Class2.

quote:
and how can I change the size of the array within the program?

C arrays can''t change size. Either use dynamic allocation (new/delete), copying your data to the new ''array'' when you change the size, or use the standard dynamic array class - std::vector.



Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]

Share this post


Link to post
Share on other sites