派生类中的部分专用化(加上奇怪的循环模式)

Partial specialization in a derived class (plus curious recurrent pattern)

本文关键字:循环 模式 派生 专用      更新时间:2023-10-16

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

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)不匹配。

我应该怎么做?

您得到的错误derived是一个类模板,并且您省略了它的模板参数。 您需要为 derived 指定模板参数:

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