title: instanceof equivalent in C++
body: <p>I'm creating a 2D game in C++ that uses levels made out of tiles. The world class has an <code>add(WorldObject* o)</code> function that can both accept a tile or an entity such as an enemy. Both the <code>Tile</code> and the <code>Entity</code> class are derived from <code>WorldObject</code>. In every case, the object should be added to the <code>entities</code> list; but if it is a tile, it should also be added to the <code>tiles</code> list.</p>
  
  <p>World.h</p>
  
  <pre><code>class World {
  private:
      list&lt;WorldObject*&gt; content;
      list&lt;Tile*&gt; tiles;
  public:
      void add(WorldObject*);
  }
  </code></pre>
  
  <p>World.cpp</p>
  
  <pre><code>void World::add(WorldObject* o) {
      content.push_back(o);
      if(*o instanceof Tile) //What do I need to put here?
          tiles.push_back(o);
  }
  </code></pre>
  
  <p>How do I check whether an object has a specific type in C++? It's nothing about typecasting and virtual functions and things like that because I don't want to invoke functions to the object at this time; I just need to add it to a separate list if it has a certain type.
  In Java, I can do <code>if(instance instanceof Class)</code>. How can I do this in C++?</p>