我正在使用模板将整数类型转换为其二进制值的字符串表示形式。我使用了以下内容:
template<typename T>
std::string ToBinary(const T& value)
{
const std::bitset<std::numeric_limits<T>::digits + 1> bs(value);
const std::string s(bs.to_string());
return s;
}
它适用于 int 但不能使用 unsigned int 编译:
unsigned int buffer_u[10];
int buffer_i[10];
...
ToBinary(buffer_i[1]); //compile and works
ToBinary(buffer_u[1]); //doesn't compile -- ambiguous overload
你能解释一下为什么吗?
编辑:
是的,我正在使用 VS2010