c++ - Accessing protected members of derived class with CRTP -


i'm using crtp, , have problem accessing protected members of derived class.

here example, close code:

template< typename self>   class {   public:       void foo( ) {           self s;           s._method( s); //error, because _method protected       }    protected:       virtual  void _method( const self & b) = 0;   };  class b : public a< b> { protected:     void _method( const b & b) {} }; 

i understood, must use friend keyword. can't understand put in class a< self>. know make void _method( const b &b) public in b, don't want it. using keywords in b impossible me either!

i found solution. answers. need change line:

s._method( s); //error, because _method protected 

to

( ( a< self> &) s)._method( s); 

and works! http://ideone.com/cjclqz


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -