Nope, consider you have two classes "Armor" and "Weapon" derived from "Object", and want to store them in single container. If you change container type to vector<Weapon>, you will not be able to store Armor in it.
Vector of automatic pointers is the best solution to this.
Thanks for all the replies. JLB's way is what I was looking for, but what if I wanted to add items statically?
For example, if you kill someone and click a button, their inventory will be added to yours. You can't just declare vector.pushback(std::make_shared<TYPE> every time because you don't know what type it'll be; it could be a Weapon or a Consumable.
Is there another way or am I just using this wrong? Because every item will be from a class derived Object; just with different functions and stats.
And then I can use these objects with their already made stats throughout my program. Maybe I'm missing something because I can't seem to do it with this way..
Quick note, the way to added inventory with the "&" operator didn't work (violation accessing memory), but making the classes pointers using new and adding them worked. Not sure why. But still, thanks!
> the way to added inventory with the "&" operator didn't work
If the address of (or a reference to) the object is taken, and then after the object is destroyed, we try to use the address (or reference) to get to the object, bad things happen.
Just make sure that the object whose address was taken out-lives the vector.