My hobbies are my passion. Whether or not I receive donations, I will continue to do what I love. If you would like to focus my efforts towards a specific project, donating will help (Use the optional instructions/comments field).
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

  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.

Comment

Wow, good info. If I ever use VS again and a dynamic cast I’ll try to remember that.

Jon · 01/12/07 07:25 AM · #

I dont even know what r u talking about, but I like your “next guy” sort of ethic.

charly.gr · 02/28/07 02:55 PM · #

Wow! That`s awesome! Thanks, really :) you are my saviour – i`ve spent a plenty of time trying my best to understand what`s happening with my C++ project and what you`ve wrote was the explanation :) thank you ones more.

Chu · 05/13/08 04:57 AM · #

Textile Help