【发布时间】:2017-10-04 12:58:43
【问题描述】:
谁能帮我理解为什么下面的代码不能编译:
#include <type_traits>
template< typename T >
class A
{};
template< typename T >
class B
{};
template< template <typename T> class GENERAL_t, // Note: GENERAL_t is either A<T> or B<T>
typename = std::enable_if_t< std::is_same<T,int>::value >
>
void foo( GENERAL_t a )
{}
错误信息:
t.cpp:67:57: error: use of undeclared identifier 'T'
typename = std::enable_if_t< std::is_same<T,int>::value >
^
t.cpp:67:65: error: no type named 'value' in the global namespace
typename = std::enable_if_t< std::is_same<T,int>::value >
~~^
t.cpp:69:15: error: use of class template 'GENERAL_t' requires template arguments
void foo( GENERAL_t a )
^
t.cpp:66:43: note: template is declared here
template< template <typename T> class GENERAL_t, // Note: GENERAL_t is either A<T> or B<T>
~~~~~~~~~~~~~~~~~~~~~ ^
3 errors generated.
这里,foo 应该采用 class A 或 class B 的实例,但前提是 A 或 B 的模板参数 T 是 int。
【问题讨论】:
标签: c++ templates c++14 type-deduction template-templates