C++ Polymorphism question?

I have a class called Object, and a class called Weapon that is a sub class of Object.

How do I put a Weapon in this vector and have it recognized as type Weapon, not Object?

vector inv_item;
note: this is what I tried but it doesnt work.

…SetItem(Weapon &newobject)
inv_item.push_back(weapon);
…SetItem(Weapon &newobject) {

inv_item.push_back(newobject);

Subscribe / Share

It's very calm over here, why not leave a comment?

Leave a Reply




Categories

Powered by Yahoo! Answers