views:

146

answers:

1

I'm trying to compile a C++ project using Microsoft VisualStudio 2008. This particular project compiles fine if you use Win32 as target platform. If I try to compile the same project for the x64 platform I get a C2593 'operator identifier' is ambiguous error in this line:

case 't':  os_ << (size_t)path->rnode->char_type;     break;

Anyone has a clue why the same line compiles fine for 32-bit but fails for 64-bit with such a high level error?

+2  A: 

Ok, got it. The problem is the size_t data type which has different sizes for the two different plattforms. The operator << is defined for a various list of data types:

StringBuffer& operator<<(unsigned short int n) { _UITOA(n); }
StringBuffer& operator<<(unsigned int n)       { _UITOA(n); }

On a 32-bit platform "unsigned int" is a perfect match for size_t. On 64-bit platforms size_t is 64 bits and doesn't match exactly on any operator declaration.

The solution is to choose the exact operator by using the correct data type:

case 't':  os_ << (unsigned int)path->rnode->char_type;     break;

Or overload the operator using size_t:

StringBuffer& operator<<(size_t)       { _UITOA(n); }
Eduard Wirch
Or unsigned long rather than size_t
Martin York
Or a template method (since they all seem to be converting to string. (PS You could use boost::lexical_cast<>()
Martin York