首页 > 解决方案 > 如何使用来自结构的成员模板化类型别名的模板模板参数

问题描述

我正在尝试使用来自结构的成员类型别名的模板模板参数,但我找不到正确的语法:

struct A
{
   template <typename T>
   using type = int;
};

template <template <typename> class C>
struct B
{
   // ...
};

B<typename A::type> b; // Does not compile: error: template argument for template template parameter must be a class template or type alias template
B<typename A::template type> b; // Does not compile: error: expected an identifier or template-id after '::'
B<typename A::template <typename> type> b; // Does not compile
B<typename A::template <typename> class type> b; // Does not compile

标签: c++c++11templates

解决方案


A::type是一个模板,而不是一个类型名。

B<A::template type> b1;  // OK
B<A::type> b2;           // OK

推荐阅读