how to check type of object in C++
<p>In java, there is a keyword "instanceof", which can be used to determine the type of object. In C++, the only solution i found so far was to use dynamic_cast. This approach  is not only bad, but it is also very expensive. The reason it is bad is because the flow of control is driven by catching exceptions. Exception in my mind should only be used for "Exceptional" situations and not to control the main flow of code. </p>

<p>Imagine a use case, where a network handler can receive different types of messages. This handler can have a long list of try catch blocks with each block trying a dynamic_cast. It could be possible that for every single message, there would be many exceptions raised, till the flow finally finds the correct type. This also kills the performance in the application as catching exception is not cheap. </p>

<p>Can you please suggest alternatives to dynamic_cast, similar to java's instanceof operator, so that i can avoid exception catching overhead?</p>

<p>UPDATE: Any solution other than RTTI would be great as RTTI is also expensive. Perhaps , i can just put string names in the messages and map strings to objects?</p>
