【问题标题】:Understanding Watch window in VisualStudio 2010了解 Visual Studio 2010 中的监视窗口
【发布时间】:2015-02-11 02:22:57
【问题描述】:

我无法理解方括号内的对象部分是什么意思([bsm::Material] 见下图)。我希望 MaterialLayer 类型的对象 ml 仅由 Object 类型(基类)的一部分 + 两个字段厚度和材料(指向 Material 的指针)组成。

那么,Visual Studio 2010 在其 Watch 窗口中显示的方括号之间的部分是什么?

这里是 Material、Object 和 MaterialLayer 类的定义:

class Object
{

public:
    // Methods
};


class Material : public Object
{
    int type;
    std::string name;
    std::vector<Property *> properties;

public:
    // Methods
};


class MaterialLayer : public Object
{
    double thickness;
    Material * material;

public:
    // Methods
};

【问题讨论】:

    标签: c++ debugging watch


    【解决方案1】:

    看起来ml 被声明为bsm::MaterialLayer*,但是通过类型转换为其分配了bsm::Material* 类型的指针:

    bsm::MaterialLayer *ml;
    bsm::Material *foo;
    ml = (bsm::MaterialLayer *)foo;
    

    这不会在编译时产生类型转换错误,但几乎肯定会导致 thicknessmaterial 中的无意义值之类的错误。

    但是,由于它们都有一个共同的父级,因此 Watch 在方括号中显示其真正的子级。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-23
      • 1970-01-01
      • 2012-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多