2

Possible Duplicate:
std::to_string - more than instance of overloaded function matches the argument list

#include <string>

int main()
{
    double randDouble = 1245.432;
    std::wstring stringDouble = std::to_wstring(randDouble);
}

When I compile this in Visual Studio 2010 I get this error

Error 1 error C2668: 'std::to_wstring' : ambiguous call to overloaded function 6

1> error C2668: 'std::to_string' : ambiguous call to overloaded function

1> d:\program files (x86)\microsoft visual studio 10.0\vc\include\string(688): could be 'std::string std::to_string(long double)'

1> d:\program files (x86)\microsoft visual studio 10.0\vc\include\string(680): or 'std::string std::to_string(_ULonglong)'

1> d:\program files (x86)\microsoft visual studio 10.0\vc\include\string(672): or
'std::string std::to_string(_Longlong)'

Can someone please explain to me why the compiler is confused and what am I doing wrong?

Community
  • 1
  • 1
Caesar
  • 9,483
  • 8
  • 40
  • 66

1 Answers1

6

This was a bug in Visual C++ 2010. It has been fixed in Visual C++ 2012.

James McNellis
  • 348,265
  • 75
  • 913
  • 977
  • To elaborate a bit on this, the particular bug was, that their standard library only provided `long long`, `unsigned long long` and `long double` overloads. So to circumvent it, you have to cast the argument to the largest type of its kind (in your case `long double`). – Christian Rau Jan 27 '13 at 01:17