C++ 从嵌套在类模板中的类模板派生,所有这些都使用类模板
我正在努力让这一切顺利进行:C++ 从嵌套在类模板中的类模板派生,所有这些都使用类模板,c++,templates,template-meta-programming,crtp,C++,Templates,Template Meta Programming,Crtp,我正在努力让这一切顺利进行: template<template<typename> class... Attributes> struct Skills { template<class DERIVED> struct Create : public Attributes<DERIVED>... {}; }; template <class T, class SKILLS> class Tester : pu
template<template<typename> class... Attributes>
struct Skills
{
template<class DERIVED>
struct Create : public Attributes<DERIVED>...
{};
};
template <class T, class SKILLS>
class Tester : public typename SKILLS::Create<Tester<T,SKILLS>>
{}
模板
结构技能
{
模板
结构创建:公共属性。。。
{};
};
模板
类测试员:公共类型名技能::创建
{}
但编译器抱怨:
错误C2518:基类列表中的关键字“typename”非法;忽略
但是,如果我不在类模板中进行派生,那么这种方法可以很好地工作
是否有机会从嵌套模板类派生?
为什么我需要这个?我正在尝试为CRTP类模板实现一个更好的接口,它允许执行以下操作:
using MyClass = ClassWithAttributes<Skills<Plus,Minus,Equal,Clear,Size>>
使用MyClass=ClassWithAttributes
你必须写
template <class T, class SKILLS>
class Tester : public SKILLS::template Create<Tester<T,SKILLS>>
{ };
模板
类测试员:公共技能::模板创建
{ };
我是说
(1) notypename
:在基类列表中,隐含参数是类型
(2) 在创建之前,您需要模板
(3) 使用SKILLS
作为Tester
的参数,而不是SKILLS
,因为您已经声明了模板参数SKILLS
(4) 记住类定义末尾的分号谢谢,就这样。这(3)只是一个打字错误,我编辑了这个。