我正在尝试使用CRTP进行实验,但我对下面的代码为什么不编译感到困惑。
template<template<class...> class CBase>
struct ComponentX : public CBase<ComponentX>
{
// This does NOT compile
};
template<template<class...> class CBase>
struct ComponentY : public CBase<int>
{
// This does compile
};您知道在CRTP情况下,模板模板参数是否有某些限制吗?
发布于 2018-09-20 08:59:26
类模板名称表示“当前专门化”(即,它是一个注入的类名),仅在类模板定义的开头{之后,在其作用域内。在此之前,它是一个模板名。
因此,CBase<ComponentX>是将模板作为参数传递给CBase的一种尝试,CBase需要一组类型。
修复方法相当简单:
template<template<class...> class CBase>
struct ComponentX : public CBase<ComponentX<CBase>> // Specify the arguments
{
// This should compile now
}; ComponentX<CBase>是您希望作为类型参数提供的专门化的名称。
https://stackoverflow.com/questions/52421194
复制相似问题