dynamic_cast throws unhandled exception in VC++ 6.0

17 05 2013


Usually we upgrade our projects to higher versions of Visual Studio IDE for getting latest Windows libraries and making our project to be compatible with latest technologies. But recently we had to downgrade one of our DLLs to VC++ 6.0 from VS2005. As first step, we created new project in VC++ 6.0, resolved all compiler errors and successfully compiled it in VC++ 6.0 IDE. But when we integrated it with client application, it started throwing unhandled exception from wherever it used dynamic_cast. 😦


We have to explicitly enable Run-Time Type Information(RTTI) for our project in VC++ 6.0 compiler. In Visual C++ 2005, RTTI is on by default.

Enabling RTTI in VC++ 6.0 Project,

1) Open the project’s Property Page

2) Click the C/C++ Tab

3) Select C++ Language Category

4) Select Enable Run-Time Type Information (RTTI) checkbox

RTTI


typeid operator also fail if we don’t enable RTTI in our project.