可能重复:
Where and why do I have to put the “template” and “typename” keywords?
我希望有一个带有单个参数的构造函数,并且仅在该参数的类型具有成员类型::t
时才启用,该成员类型必须是某个其他类型的子类型。我正在使用类型特征,代码如下所示:
#include <type_traits>
struct Y{};
struct X{
//Only allow if T has a type member T::t which is a subtype of Y
template <typename T>
X(T* t, std::enable_if<std::is_base_of<Y, typename T::t>::value, int>::type e = 0){}
};
然而,g ++抱怨如下:
test/test.cpp:8:75: error: ‘std::enable_if<std::is_base_of<Y, typename T::t>::value, int>::type’ is not a type
我做错了什么?
答案 0 :(得分:5)
您必须向typename
添加std::enable_if<...>::type
才能解决此问题......