C++ C++;具有参数化基类的CRTP?

C++ C++;具有参数化基类的CRTP?,c++,templates,crtp,C++,Templates,Crtp,我正在尝试使用带有一个小变化的CRTP。我有一个派生类模板,希望将其应用于多个基类。但这要么是不可能的,要么就是语法不对。以下代码未编译,但希望能说明我想要实现的目标: template <class Derived> struct BaseCats { /* ... */ }; template <class Derived> struct BaseDogs { /* ... */ }; // .... template <class Derived> st

我正在尝试使用带有一个小变化的CRTP。我有一个派生类模板,希望将其应用于多个基类。但这要么是不可能的,要么就是语法不对。以下代码未编译,但希望能说明我想要实现的目标:

template <class Derived> struct BaseCats { /* ... */ };
template <class Derived> struct BaseDogs { /* ... */ };
// ....
template <class Derived> struct BaseN { /* ... */ };

template <template <class> class Base>
struct Wrapper 
    : 
    Base<Wrapper> // compile error - Wrapper is not a complete type
{
    Wrapper(int n) 
    { 
       // I do not want to rewrite or forward this 
       // constructor or Wrapper's operators
    }
};

typedef Wrapper<BaseCats> Cats;
typedef Wrapper<BaseDogs> Dogs;
// ...
typedef Wrapper<BaseN> MyTypeN;
模板结构BaseCats{/*…*/};
模板结构BaseDogs{/*…*/};
// ....
模板结构BaseN{/*…*/};
模板
结构包装器
: 
基//编译错误-包装器不是完整类型
{
包装器(int n)
{ 
//我不想重写或转发此文件
//构造函数或包装器的运算符
}
};
猫;
狗;
// ...
typedef包装器MyTypeN;
这能做到吗

编辑:

我在这里想要实现什么

我重新命名了上面的一些代码,以使用“狗和猫”的比喻。可能存在以下功能:

void BaseCats<Derived>::print() const 
{ 
    std::cout << (static_cast<const Derived *>this)->n << " cats\n"; 
}
void BaseCats::print()常量
{ 

std::cout n您的编译错误可以通过以下方法解决:

Base<Wrapper<Base> >
Base

你忘了模板参数。

你想用这种设计实现什么?你意识到你想让
Base
派生出
派生出
它本身从
派生出
Base
,等等吗?你可能应该解释你的目标是什么,而不是你是如何做到的e实现它,以便我们可以提出替代方案。+1用于有趣的设计。不确定它会有多有用yetAh是的,我确实想到了,但假设我必须编写
Base
@paperjam,只要Base不继承包装器,这种情况就不会发生。