我尝试使用gcc 4.9.2在 我收到了以下错误: 奇怪的是,代码在Linux下编译(gcc 4.8.3)(http://goo.gl/uEQYB8)。我的Cygwin环境或编译器会出现什么问题?#include <type_traits>
template <template <typename...> class C, typename... Ts>
class Foo
{
template <typename T> struct IsFoo : std::true_type {};
template<typename T> typename std::enable_if<IsFoo<T>::value>::type bar(T v);
};
template <template <typename...> class C, typename... Ts>
template <typename T>
typename std::enable_if<Foo<C, Ts...>::IsFoo<T>::value>::type
Foo<C, Ts...>::bar(T v)
{
return;
}
$ gcc -std=c++11 b.cpp
b.cpp:13:15: error: parse error in template argument list
typename std::enable_if<Foo<C, Ts...>::IsFoo<T>::value>::type
^
b.cpp:13:48: error: too many template-parameter-lists
typename std::enable_if<Foo<C, Ts...>::IsFoo<T>::value>::type
^
答案 0 :(得分:0)
解析错误是因为:
template <template <typename...> class C, typename... Ts>
template <typename T>
typename std::enable_if<Foo<C, Ts...>::IsFoo<T>::value>::type
Foo<C, Ts...>::bar(T v) { /**/ }
应该是:
template <template <typename...> class C, typename... Ts>
template <typename T>
typename std::enable_if<Foo<C, Ts...>::template IsFoo<T>::value>::type
// ~~~~~~~^
Foo<C, Ts...>::bar(T v) { /**/ }
,如Where and why do I have to put the “template” and “typename” keywords?
中所述