c++ - 了解 Visual Studio 2010 中的监 window 口

标签 c++ debugging watch

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

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

enter image description here

以下是 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
};

最佳答案

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

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

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

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

关于c++ - 了解 Visual Studio 2010 中的监 window 口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27442543/

相关文章:

c++ - 在 C++ 中打印一个数组

c++ - 使用友元函数迭代另一个类的私有(private)成员

python - 为什么assertEquals()参数的顺序是(预期的,实际的)?

node.js - 当文件中有更新时,如何从nodejs中的fs.watch获取更新的数据

刷新输出上的 linux watch 横幅

c++ - boost::math::pdf,它如何计算只有 1 个值的正态分布的概率?

java - 如何调试位于堆上的对象?(eclipse-java)

c - 在 C 中使用 getopt 作为命令行参数

javascript - 创建Trigger看文档值mongoDB发送邮件

c++ - 错误-根据g++未声明继承的类字段