Possible Duplicate:
Where and why do I have to put the “template” and “typename” keywords?
I want to have a constructor that takes a single argument and is only enabled if the type of that argument has a member type ::t
which must be a subtype of some other type. I am using type traits for this and the code looks like this:
#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){}
};
However, g++ complains the following:
test/test.cpp:8:75: error: ‘std::enable_if<std::is_base_of<Y, typename T::t>::value, int>::type’ is not a type
What have I done wrong?
You have to add a typename
to std::enable_if<...>::type
to resolve this...