I’m getting the following error when I compile the following code on Visual Studio 2008 / Windows SDK 7
const UINT a_uint;
UINT result;
throw std::runtime_error( std::string("we did ") + a_uint +
" and got " + result );
Ironically, I ended up with this result:
error C2782: 'std::basic_string<_Elem,_Traits,_Alloc> std::operator +(
const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem
)' : template parameter '_Elem' is ambiguous
Can someone explain why the error message doesn’t explain the real problem (that there is no operator for +ing ints to strings)?
You can reduce that to this
You try to add an unsigned int to a string. That does not make sense, and the
std::stringclass does not need to take any precautions to add implicit conversions tocharhere because that would hide such potential programming bugs.Try to convert the unsigned int to
std::stringinto a decimal/hexadecimal/octal/etc form and then concatenate (you can do that usingstd::ostringstreamorboost::lexical_cast) or fix the bug in other ways you see fit.