Question: 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??

Answer: 
Implement a function name() in each subclass.
Without using special tricks to give your base class information about derived types, there is no way for it to know what subtype an instance is. The simplest way to do this is, as @Joachim Wuttke suggests, to create a virtual function forcing derived classes to implement a name() method.

However, if you want to get a little fancier, the curiously recurring template parttern [CRTP](http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern) offers a more elegant, if esoteric solution:

```
#include <typeinfo>
#include <string>
#include <iostream>

template <class T>
class Animal {
public:
    virtual ~Animal() {};  // a base class
    std::string name() {
        return typeid(T).name();
    }
};

class Cat: public Animal<Cat> {

};

class Dog: public Animal<Dog> {

};

int main( int argc, char* argv[] ){
    Cat c;
    Dog d;

    std::cout << c.name() << std::endl;
    std::cout << d.name() << std::endl;

}

```

result (g++):

```
3Cat
3Dog

```

result (vs2008):

```
class Cat
class Dog

```

Note that as others have said typeid's name mangling is platform/compiler dependent, so to go from the names above back to the class you have to implement a platform/compiler-dependent demangling routine. Not especially difficult, but it does take away from the elegance of the solution.