在“任意命名空间”(C ++)中调试数据 [英] Debugging data in 'anynomous namespaces' (C++)

查看:128
本文介绍了在“任意命名空间”(C ++)中调试数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我有一个客户的崩溃转储文件。我可以跟踪这个问题,直到一个类可能包含不正确的数据,但我只有一个void指针的类,而不是一个真正的指针(void指针来自一个窗口属性,因此它是一个void指针) 。不幸的是,我想将指针转换到的类是一个匿名的命名空间,如下所示:

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.

如果Visual Studio 2005刚刚显示指针值,在观察窗口中使用ptr。
如果我使用(MyClass *)ptr,调试器告诉我它不能转换它。

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.

如何将ptr转换为MyClass-指针?

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

注意:我最终可以使用一个愚蠢的命名空间(像源文件的名称),然后使用using namespace预期更好的解决方案。

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.

推荐答案

MSDN 。它看起来不像在Watch窗口内有一个很好的解决方案(你可以从列表中获得你的类的装饰名称我猜)。

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.

这篇关于在“任意命名空间”(C ++)中调试数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆