I am trying to get the address of a base class protected member variable.
Please help me understand what's wrong with this code:
class A { protected: int m_; }; class B : public A { public: void Foo() { auto p1 = m_; // works but not what I want (B's member) auto p2 = &m_; // works but not the the address which I'm looking for (B's member) auto p3 = A::m_; // works but still not the address of the variable (A's member but not the address) auto p4 = &A::m_; // doesn't work -> int A::m_’ is protected within this context auto p5 = static_cast<A*>(this)->m_; // doesn't work -> int A::m_’ is protected within this context auto p6 = &static_cast<A*>(this)->m_; // doesn't work -> int A::m_’ is protected within this context } private: int m_; }; Thanks
Gil