Understanding Watch window in VisualStudio 2010

独自空忆成欢 提交于 2019-12-10 11:04:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!