<p>I'll phrase this in the form of an example to make it more clear.</p>

<p>Say I have a vector of animals and I want to go through the array and see if the elements are either dogs or cats?</p>

<pre><code>class Dog: public Animal{/*...*/};
class Cat: public Animal{/*...*/};

int main()
{
vector&lt;Animal*&gt; stuff;
//cramming the dogs and cats in...

for(/*all elements in stuff*/)
//Something to the effect of:  if(stuff[i].getClass()==Dog) {/*do something*/}

}
</code></pre>

<p>I hope that's sort of clear. I know about typeid, but I don't really have any Dog object to compare it to and I would like to avoid creating a Dog object if I can.</p>

<p>Is there a way to do this? Thanks in advance.</p>

You can use
```
dynamic_cast
```
, as long as the vector contains Animal pointers.
```
```
vector <Animal *> stuff;

for(int i=0;i<stuff.size();i++) {
    Dog *pDog = dynamic_cast <Dog *> (stuff[i]);
    if(pDog) {
        // do whatever with the dog
    }

    Cat *pCat = dynamic_cast <Cat *> (stuff[i]);
    if(pCat) {
        // and so on
    }
}
```
```
but you should be aware that this is generally not the best practice. You should try to work with polymorphism, not against it. In other words, try to write a virtual
```
Animal
```
function that
```
Dog
```
and
```
Cat
```
override, and let the compiler automagically call the right one.
(Also,
```
dynamic_cast
```
is relatively slow, so too many of them will hinder performance; whereas a virtual function call is general just a single instruction.)