Thu
Jan
11
2007
C++ dynamic_cast
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
- Open Project Settings and select the project
- Select the C/C++ tab
- Change Category to “C++ Language”
- Check “Enable Run-Time Type Information (RTTI)”
- 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.
Comment
Wow, good info. If I ever use VS again and a dynamic cast I’ll try to remember that.
I dont even know what r u talking about, but I like your “next guy” sort of ethic.




