C++ dynamic_cast

Categories: Code, Projects

Posted:

I just spent way too much time trying to figure out a work related problem. A shared piece of code was consistently failing on the same line with a KERNEL32.DLL Exception 0xe0fd7363. The Visual Studio 6 debugger showed the proper information and the object was indeed valid.

<derived_type> *p = dynamic_cast<derived_type *>(pObj);

Searches on google and msdn yielded me nothing useful. I finally asked my “Crazy Russian” friend who enlightened me to RTTI and how if you want to use a dynamic cast in C++ code, you need to turn that on for the project.

How To

  1. Open Project Settings and select the project
  2. Select the C/C++ tab
  3. Change Category to “C++ Language”
  4. Check “Enable Run-Time Type Information (RTTI)”
  5. Rebuild All on the project

It makes perfect sense now that I know the answer, but this is something I figured the compiler would do automatically and I wouldn’t have to enable. I’m sure it would have been a few more days before I figured this out. I’m posting this for the “next guy”. Hopefully their searching will be more fruitful.

blog comments powered by Disqus