问题
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).
So, what is the part between square brackets, shown by Visual Studio 2010 in its Watch window?
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
};
回答1:
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;
This does not generate a typecast error in compile-time but will almost certainly lead to errors like nonsense values in thickness
and material
.
However, since they both share a common parent, Watch shows its real child in square brackets.
来源:https://stackoverflow.com/questions/27442543/understanding-watch-window-in-visualstudio-2010