user4469411
user4469411

Reputation:

Private members visible outside the class

Why is it that I can see private members of my class in a Quick Watch window when the breakpoint is outside that class?

My breakpoint is in ConsoleApplication.cpp My class is defined in XmlSignature.h

I can see these private members: Transforms_Root_element, xmlDocument

Here's my class:

ref class XmlReference
{
public:
    XmlReference(String^ URI);
    virtual ~XmlReference();

    String^ URI;
    XmlElement^ Reference_element;

    String^ ns_ds = "http://www.w3.org/2000/09/xmldsig#";

    XmlNode^ AddTransform(String^ strAlgorithm);
    XmlNode^ AddTransform(String^ strAlgorithm, String^ strParameterName, String^ strParameter);

    List<XmlNode^>^ Transforms = gcnew List<XmlNode^>;
private:

    XmlNode^ Transforms_Root_element = nullptr;
    XmlDocument^ xmlDocument;

    //Called by AddTransform
    XmlNode^ CreateTransformElement(String^ strAlgorithm);
};

This is what I can see:

enter image description here

Upvotes: 0

Views: 72

Answers (1)

ta55e
ta55e

Reputation: 204

That is a feature and helps when debugging :-). Class member visibility is ensured by the compiler to enforce object orientated programming. As @Medinoc observed, .net runtime also protects private and protected memory of a class from being accessed from other contexts.

In any case, the debugger has full access to the memory and can show all member content.

Upvotes: 1

Related Questions