问题描述
我不明白在方括号内的对象的部分是什么意思([bsm :: Material]见下图)。我希望类型MaterialLayer的对象ml只由类型Object(基类)+两个字段厚度和材料(指向Material的指针)的一部分组成。
I cannot understand what the part of the object within square bracket means ( [bsm::Material] see pic below ). I would expect the object ml of type MaterialLayer to be composed only of a part of type Object (base class) + two fields thickness and material (a pointer to Material).
因此,Visual Studio 2010在其Watch窗口中显示的方括号之间是什么?
So, what is the part between square brackets, shown by Visual Studio 2010 in its Watch window?
这里是Material,Object和MaterialLayer类的定义:
Here is the definition of the Material, Object, and MaterialLayer classes:
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 *
通过类型转换分配给它:
It looks like ml
is declared as bsm::MaterialLayer*
, but a pointer of type bsm::Material*
was assigned to it by typecasting:
bsm::MaterialLayer *ml;
bsm::Material *foo;
ml = (bsm::MaterialLayer *)foo;
这在编译时不会产生typecast错误,但几乎肯定会导致错误, thickness
和 material
。
This does not generate a typecast error in compile-time but will almost certainly lead to errors like nonsense values in thickness
and material
.
两者都共享一个共同的父,Watch显示其真正的孩子在方括号。
However, since they both share a common parent, Watch shows its real child in square brackets.
这篇关于了解VisualStudio 2010中的监视窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!