我正在使用静态多态性(CRTP 方法)来创建类层次结构。这个想法是在基类中使用派生类中定义的结构。但是,VC10 会产生以下错误:
error C2039: 'param_t' : is not a member of 'D'
和英特尔 C++ 生成以下错误:
error : incomplete type is not allowed
这Derived::param_t
是一种struct
类型,应该正常编译,这很令人困惑。请指出代码中的问题。谢谢。
// 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);
}