i'm self learning C++ (using schaum's programming with c++ book), and i can't find anything in the book that explains how to create a collection of objects?
For example say you have a class of books, and a class of stores, and you want to create a collection of book objects in the store class, how would this be implemented?
I'm confused as with arrays you have to give a set size don't you? So what if you don't yet know the size needed? I'm assuming an array is not the best thing to use...
Also sorry if the book/store class example is a bad example. :)
You seem to be catching on quickly. No, arrays are generally not the best thing to use.
The standard library has a number of collection classes such as vector, deque, list, set, map, etc. From the sound of things, you might want a vector or a multimap. A vector is pretty much like an array, except that it resizes as needed when you insert objects. A map gives you the ability to look things up based on a field, such as looking a book up based on the title or author.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With