3

最小的例子:

template<template<class ...> class>
struct templ {};

template<class T>
using special = templ<T::type>;

int main() {}

铿锵++:

test.cpp:5:23: error: template argument for template template parameter must be a class template or type alias template
using special = templ<T::type>;

确实,我的意思是说这T::type是一个类模板,例如

struct detail1 {
    template <class T>
    using type = std::vector<T>;
};

struct detail2 {
    template <class T>
    struct type {};
};

但是怎么能这么说呢?g++ 建议使用typename T::type,但这对我来说是错误的,实际上,这并不能解决错误。

4

1 回答 1

7

您需要指定这type是一个模板:

template<class T>
using special = templ< T::template type>;

这是必需的,因为T::type它依赖于模板参数T

另请参阅我必须在哪里以及为什么必须放置“模板”和“类型名称”关键字?

于 2015-02-17T10:21:13.477 回答