   [C++] Access to protected member of a virtual base class
  Hi, I am fighting with a tiny problem.At home I am using MSVC++ 2003 toolkit and the following code tells me that I cannot access a protected member function of the virtual base class although I inherit public.It tells me that I maynot access dosomething() in test(), however at university I tried this with g++ and it works fineclass base{   protected: virtual void dosomething()=0;};class inher : public base{   public: void test() {    dosomething(); };   protected: void dosomething() { }; void lala() {    dosomething(); };};
0 error(s), 0 warning(s)MS VC++ 2005 express.Maybe your compiler expect the "virtual" keyword in inher ?   ;  tested both, yesterday,I ll check it out again when I am at home, I hope its not a compiler bug, I had to recompile a ton of libraries when switching to another compiler   ;  MSVC 2003 gives me no trouble with your sample code.   ;  So I finally found out out whats been wrong with my codeYou cannot access the protected members of a base class if you reference it via a pointer. You need to make sure the instance you reference is of the same type as your derived class from which you access the memberbase *p = new derived();p->protectedfunc(); is invalid, see c++ standard.thx   ;  That's because it's a protected function, so can only be accessed by functions inside the class.   ;  I did access the function via a baseclass pointer from inside a function of a derived class, but thats not allowed by the C++ standard, you had to make sure the object the base class pointer  points to is of the same type as your derived class.I certainly know that accessing protected and private functions from outside a class is forbidden.   