Hello. I'm learning C++ out of Sams Teach Yourself C++ in 24 Hours and Accelerated C++ Practical Programming by Example. I've heard these are both good references. Anyway, I just learned about classes and I was wondering how one makes an array of class objects. here is the Cat class I made (no, not exactly the same as the one from the book, but just about :mrgreen: . . .
I think that I have the right method for initializing the array. I am doing Cat pack [8];
however. I think I'm doing it wrong when trying to call a Cat member function to a Cat object in the array. I tried pack.at(0).setage(4); which turned up a lot of errors.
Is this something that can only be accomplished using pointers? I haven't learned enough about pointers yet to do that. If it requires a pointer, I understand and will wait until I learn more, i'd just like to know. Thanks in advance.
arrays start out at 0 and go up... if you declared pack[8] the elements go from 0-7. and when you use arrays you have to include the [?] where you use it at with ? being the position you want to use.
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.