views:

203

answers:

1

Recently, I got a crash dump file from a customer. I could track the problem down to a class that could contain incorrect data, but I only got a void-pointer to the class, not a real pointer (void-pointer came from a window-property, therefore it was a void-pointer). Unfortunately, the class to which I wanted to cast the pointer to, was in an anonymous namespace, like this:

namespace
   {
   class MyClass
      {
      ...
      };
   }

...
void *ptr = ...
// I know ptr points to an instance of MyClass,
// and at this location I want to cast ptr to (MyClass *) in the debugger.

Using "ptr" in the watch window if Visual Studio 2005 just shows the pointer value. If I use "(MyClass *)ptr", the debugger tells me it cannot cast to it.

How can I cast the ptr to a MyClass-pointer?

Note: I could eventually use a silly-named namespace (like the name of the source file), and then use a "using namespace", but I would expect better solutions.

+3  A: 

This is mentioned in MSDN. It doesn't look like there's a nice solution within the Watch window (you can get the decorated name of your class from a listing I guess).

Your "silly-named namespace" idea would work okay, you could also just declare an identical class with a silly name and cast to that type instead.

Sumudu Fernando