我有一个函数:模板参数类型
template<class T>
static string
format(T ui, T sentinal, char listSeparator)
{
stringstream s;
if (ui == sentinal)
{
s << "n/a" << listSeparator;
}
else
{
s << ui << listSeparator;
}
return s.str();
}
函数被调用的方法是:
output << format(field1,Backend::NA_Value, csvSeparator);
output << format(field2,Backend::NA_Value, csvSeparator);
/// ...etc
此前field1
和field2
是类型unsigned int
的。 决定将这些类型更改为unsigned long long
。 但发生编译错误:
std::string format(T,T,char)' : template parameter 'T' is ambiguous
main.cpp(39) : see declaration of 'format'
could be 'Juint'
'unsigned __int64'
什么是该NA_Value的原因,它被定义为:??
static const Juint NA_Value = (Juint) -1;
typedef unsigned int Juint
它不能老是确定型板T?! 从编译器决定关于__int64的地方?
对于你的后一种选择,在这种情况下,比较不应该失败;会吗? (无符号整数与无符号长整数)。但是,这个警报当然是重要的。 – leemes