I'm using static polymorphism (CRTP method) to create class hierarchy. The idea is to use a struct defined in derived class in base one. However, VC10 generates following error:
error C2039: 'param_t' : is not a member of 'D'
and Intel C++ generates following error:
error : incomplete type is not allowed
It's quite confusing that Derived::param_t
is a struct
type and shall be compiled normally. Please point out the problem in the 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);
}