2016-09-26 6 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; 
} 

MyTAのデフォルト引数として使用する場合、コンパイラ(G ++ 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