Jump to content
  • Advertisement

Archived

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

xiros

array of a class of a class

This topic is 5754 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!