Possible Duplicate:
“What happened to my SFINAE” redux: conditional template class members?的std :: enable_if串/ char类型
为什么我不能传给其他的参数在我的模板类?我试图启用一个特定的参数只有当传递的类型是一个文字类型。如果不是,请接受其他类型,但不要启用区分大小写参数。
为什么下面不能编译?
#include <iostream>
#include <type_traits>
template<typename T>
struct is_literal
{
enum{value = false};
};
template<>
struct is_literal<char>
{
enum{value = true};
};
template<>
struct is_literal<char*>
{
enum{value = true};
};
template<>
struct is_literal<const char*>
{
enum{value = true};
};
template<typename Char, typename Traits, typename Alloc>
struct is_literal<std::basic_string<Char, Traits, Alloc>>
{
enum
{
value = true
};
};
template<typename T>
class Test
{
public:
bool Contains(T DataType, typename std::enable_if<is_literal<T>::value, bool>::type CaseSensitive = true);
};
template<typename T>
bool Test<T>::Contains(T DataType, typename std::enable_if<is_literal<T>::value, bool>::type CaseSensitive)
{
return true;
}
int main()
{
Test<int> F; //This line gives errors.. It gives none if I pass char, char*, const char*, std::string.
F.Contains(1);
}
你会得到什么错误?请将其粘贴(准确地)并指出它所指的是哪一行。 –