I have a basic question in C ++, which unfortunately puzzles me. I recently came across an article that uses down-casting to access a private member of a class 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 the hack hackP class as follows:
class hackP: public P { public: dummy *m_p; };
which apparently gets access to class P to the private member m_p with a code snippet like
P parent = ...; hackP *hp = (hackP*)&parent;
Any help would be appreciated.
source share