i'm using static polymorphism (crtp method) create class hierarchy. idea use struct defined in derived class in base one. however, vc10 generates following error:
error c2039: 'param_t' : not member of 'd'
and intel c++ generates following error:
error : incomplete type not allowed
it's quite confusing derived::param_t
struct
type , shall compiled normally. please point out problem in code. thanks.
// base class template<typename derived> struct base { typedef typename derived::param_t param_t; //error c2039 void setparam(param_t& param); const param_t& getparam() const; ... }; // derived class class d: public base<d> { public: struct param_t { double a, b, c; }; d(param_t& param):param_(param) {} ... protected: param_t param_; }; int main() { d::param_t p = {1.0, 0.2, 0.0}; d *pd = new d(p); }
you can't use types derived class in base class definition. can use inside bodies of member functions. problem typedef typename derived::param_t param_t
resolved class d: public base<d>
when compiler doesn't know yet nested types of d. member functions compiled after actual instantiation of d when definition of d available.
i think in case can't use crtp method.
Comments
Post a Comment