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
Post a Comment