2016-09-26 80 views
4

考虑以下几点:使用可变参数模板的一个特例用作模板参数

template <class...> 
struct MyT; 

template <class T> 
struct MyT<T> {}; 

template <template <class> class TT = MyT> struct A {}; // fine 

using B = A<MyT>; // does not compile 

int main() { 
    return 0; 
} 

MyT被用作A默认参数时,编译器(克++ 5.4.0)是高兴。然而,当它被用于实例A,故事不同的是:

temp.cpp:19:16: error: type/value mismatch at argument 1 in template parameter list for ‘template<template<class> class TT> struct A’ 
using B = A<MyT>; 
       ^
temp.cpp:19:16: note: expected a template of type ‘template<class> class TT’, got ‘template<class ...> struct MyT’ 

我可以通过引入一个别名解决它:

template <class T> 
using MyTT = MyT<T>; 

using B = A<MyTT>; // fine 

的问题:什么是错误的原因是有没有引入别名的解决方案?

编辑请注意,A被声明为具有所示的模板模板参数,并且不会被更改。

+0

使用'template