Hi everybody! I´m trying to make this program where i store in a vector different types of derived objects from a single base class. So i declare the vector like this:
vector<BaseClass> vec;
then, assuming that all derived objects are, naturally, base class objects i push a DerivedClass object into the vector:
vec.push_back(new DerivedClass(...));
When i pop one object from the vector, to know what kind of object i´m dealing with, i made the atribute "type" and the respective get method(getType()) in the base class. Then i do the following, wich gives a cast compilation error :
for(int i=0; i<vec.size(); i++){
if(vec[i].getType() == ...)
DerivedClass *obj = dynamic_cast<DerivedClass*> (vec[i]);
}
I´ve tried also the static cast and gives the same result. I´d be very gratefull for any help with this. Thanks for your attention.