considere a simle class stDeriv which inherits from stBase. I'am surprised to see that we cannot access to the stDeriv class members through a stBase reference.
Below the basic example to illustrate my point :
#include <fstream> // std::ifstream #include <iostream> // std::cout using namespace std; typedef struct stBase { public: virtual ~stBase() { ; } stBase(int iB) { iB_ = iB; } // Copy operator stBase &operator=(const stBase &src) { iB_ = src.iB_; return *this; } virtual void Hello() { cout << " Hello from stBase" << endl; } private: int iB_ = 0; } stBase; typedef struct stDeriv : public stBase { public: int iD_ = 0; stDeriv(int iB) : stBase(iB), iD_(0) { ; } virtual void Hello() { cout << " Hello from stDeriv" << endl; } // Copy operator stDeriv &operator=(const stDeriv &src) { iD_ = src.iD_; return *this; } } stDeriv; int main(int, char *[]) { int iErr = 0; stBase aBase(0); stDeriv aDeriv(1); stDeriv &rDeriv = aDeriv; stBase &rBase = aBase; rBase.Hello(); // OK result : "Hello from stBase" rDeriv.Hello(); // OK result : "Hello from stDeriv" rBase = rDeriv; // KO!!! Cannot access to aDeriv.iD_ through rBase !!! rBase.Hello(); // KO!!! result : "Hello from stBase" !!! return iErr; } Why do I fail to access to stDeriv::iD_ through rBase after "rBase = rDeriv;" ?
typedef struct A {} A;construct is a C-ism that, while formally valid, has no use in C++.rBaseis a reference tostBase. Look at the definition of thestBasestruct. Does it have aniD_member? No, it doesn't, and that's why you can't access it.rBase = rDeriv;does not change the reference, but the referred-to object: in your code it's equivalent toaBase = aDeriv;.