... and if it's important that you can identify which member of the vector is cat, or dog, or whatever, you could use an enum to define meaningful sumbols, e.g.
enum AnimalType
{
CAT = 0, // Don't actually need the "= 0", but it makes things clear
DOG,
BIRD,
// Define any other symbols here
NUM_ANIMALS // Final symbol in the enum gives you the number of previous symbols
};
Animals cat;
Animals dog;
Animals bird;
std::vector<Animals> myAnimals(NUM_ANIMALS);
// Put my animals into the vector
myAnimals[CAT] = cat;
myAnimals[DOG] = dog;
myAnimals[BIRD] = bird;
// Access the details for bird
doSomething(myAnimals[BIRD]);
// Iterate over all animals
for (i = 0; i < NUM_ANIMALS; ++i)
{
doSomething(myAnimals[i]);
}
Do you really need to know how many instances of the class have been created in your program, or just the number that are in the container that you're using? Usually it's the latter, and if you put the objects in a vector then you can use vector::size() to tell how many are in the container.