Know the class of a subclass in C++

By : PaulG

I haven't done C++ in at least 7 years and am suddenly knee deep in a C++ project. I would like some guidance with the following:

I have a class called Animal, and I have 3 classes that inherit from Animal: Cat, Dog and Bird. I have created a list object and am using it to store type Animal.

This list can contain Cats Dogs and Birds, when I am iterating through this list of Animals, I would like to know the immediate type of each Animal (whether it's a Cat, Dog or Bird).

When I say typeid(animal).name(); it gives me Animal, which is true, but I would like to know what kind of Animal.

Any ideas?? Should I use enums??

By : PaulG

This video can help you solving your question :)
By: admin