From the linked article, it can be seen that you are referring to typeid
and dynamic_cast<>
. You should make this explicit in the question, as you will soon see that many people will jump straight without browsing through the links.
Now, how/when are they used? The simplest answer is that this should not generally be used. In most cases a well designed program does not need to perform runtime type checks, and if you find yourself doing it, then chances are that your design is in trouble.
Of course there are exceptions to all things, and in particular the example that @Sga gave is a really good one. In boost::any
the library performs type-erasure to be able to hold any object inside the type, and then it uses RTTI manually in any_cast
when extracting the value to verify that the type of the actual object is correct. Now, this is not common either, most programs don't use type-erasure and when they do, very few times they need to analyze the type at runtime.