1

我想使用奇怪的循环模式从模板基类派生:

template<typename A, typename B>
struct base
{
    typedef A type;
};

template<typename B>
struct derived : public base<derived, B>
{
   // Own attributes.
};

但是编译器(g++ 4.7.2)告诉我参数(派生/A)不匹配。

我该怎么做?

4

1 回答 1

5

您收到错误是因为 d derivedis a class template,并且您遗漏了它的模板参数。您需要指定模板参数derived

template<typename B>
struct derived : public base<derived<B>, B>
{
   // Own attributes.
};
于 2012-12-13T16:15:04.623 回答