I have a basic C++ question that unfortunately baffles me. Recently I ran across an article that uses down-casting to access a class's private member using down-casting. My question is why does it work?
Given that I have a parent class P with a private member m_p of type dummy* then the method used was to create a hack class hackP as follows:
class hackP: public P {
public:
dummy *m_p;
};
which apparently gains access to class P
private member m_p
using a code snippet like
P parent = ...;
hackP *hp = (hackP*)&parent;
// access parent m_p as hp->m_p
Any help would be appreciated.