繁体   English   中英

CRTP和模板模板参数限制

[英]CRTP and template template parameters limitation

我正在尝试使用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的情况下模板模板参数是否有一些限制?

类模板名字代表“当前专精”(即它是一个注入的类名)仅开通后{类模板定义的,它的范围内。 在此之前,它是一个模板名称。

因此, CBase<ComponentX>试图将模板作为参数传递给CBase ,后者需要一组类型。

修复很简单:

template<template<class...> class CBase>
struct ComponentX : public CBase<ComponentX<CBase>> // Specify the arguments
  {
  // This should compile now
  }; 

ComponentX<CBase>是您希望作为类型参数提供的特化的名称。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM