内部模板 class 作为模板模板参数

Inner template class as template template parameter

我有一个 class 接受模板模板参数:

template <template <typename> class F>
class A {};

还有另一个模板化的 class 和一个内部模板化的 class:

template <typename T>
class B {
  public:
    template <typename U>
    class C {};
};

我希望能够在模板上下文中使用 C 作为 A 的模板模板参数:

template <typename T>
using D = A<B<T>::C>;

但是,这会导致错误消息:

"template argument for template template parameter must be a class template or type alias template"

我假设我在 D 的声明中遗漏了一些 typenametemplate 的魔法咒语,但我和错误消息不是特别有用。

报错提示B<T>::C不是模板,因此与A的模板模板参数不匹配。

您需要使用template keyword to tell the compiler that the dependent name B<T>::C(取决于模板参数T一个模板。

template <typename T>
using D = A<B<T>::template C>;
//                ~~~~~~~~