c++ - Curiously Recurring Template Pattern and statics in the base class -
so this answer i'm looking @ implementing problem crtp. have problem. in static base class have 2 sets of functions. 1 takes std::vectors , 1 takes standard c-style array. in base class define static function calls non-std::vector function.
however when derive base class seem no longer able access public static function in base class (which thought could).
template< class derived > class base { public: static void func( std::vector< float >& buffer ) { func( &buffer.front(), buffer.size() ); } static void func( float* pbuffer, int size ) { derived::func( pbuffer, size ); } };
i define derived class follows:
class derived : public base< derived > { public: static void func( float* pbuffer, int size ) { // stuff } };
however when try call static function in base class:
derived::func( stlvec );
from derived class throws compilation error:
error c2665: 'main' : none of 2 overloads convert argument types 1> c:\development\base.h(706): 'void func( float*, int )
i assumed able call public static defined in base class derived class. appears not case, ... can suggest workaround doesn't mean having implement std::vector function in every 1 of derived classes?
func
in derived class hides base members same name. use using
declarative bring names base class derived class.
class derived : public base< derived > { public: using base<derived>::func; //rest.. };
Comments
Post a Comment