【发布时间】:2012-09-11 12:53:53
【问题描述】:
可能重复:
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
我做错了什么?
【问题讨论】:
标签: c++ sfinae typetraits enable-if