最近,我从客户那里得到了一个崩溃转储文件。我可以将问题跟踪到一个可能包含不正确数据的类,但我只有一个指向类的void指针,而不是一个真正的指针(void-pointer来自window-property,因此它是一个void-pointer) 。 不幸的是,我想将指针强制转换为的类是在匿名命名空间中,如下所示:
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.
如果Visual Studio 2005只显示指针值,则在监视窗口中使用“ptr”。 如果我使用“(MyClass *)ptr”,调试器会告诉我它无法转换为它。
如何将ptr转换为MyClass指针?
注意:我最终可以使用一个愚蠢命名的命名空间(比如源文件的名称),然后使用“using namespace”,但我希望有更好的解决方案。