stl vector class
let's say i have an array of apple pointers:
or i use vector classes to do this:
let's say i wanted to access an item of the apple class
does c++ allow the last snippet of code if vector classes are used? what would need to be changed?
cout << apples->flavor; //prints "delicious"
Your declaration of the vector is wrong, to create a vector of apple pointers with an initial size of 100 elements you wuold do this:
The rest of your code should work.
forgot that with vector arrays i don't have to specify its size ahead of time. with a little poking and proding the program should work. thanks
You dont have to specify the size of a vector initially, but you must also consider how many times you are going to call push_back on the vector since this can be a very time/memory consuming operation if it is called often.