ID: Q87640
- Microsoft C/C++, version 7.0
- Microsoft Visual C++ for Windows, versions 1.0, 1.5
In an application that uses the Microsoft Foundation Classes, a statement intended to send a single character to the predefined afxDump stream cause the compiler to generate the following error message:
error C2593: 'operator <<' is ambiguous
In C++, normal character constants have type "char," and multi-byte character constants have type "int." The afxDump stream has type "CDumpContext &"; therefore the compiler can choose either of the following versions of the "operator<<":
CDumpContext& operator<<(BYTE); // BYTE is an unsigned char
CDumpContext& operator<<(int);
To eliminate this error message, use a string instead of using a single character. This same error occurs when an application attempts to serialize any type that is not specifically supported. For example, as the sample code below demonstrates, replace '\n' with a "\n". In that case, the code would choose the following operator<<:
CDumpContext& operator<<(const char FAR *);
Microsoft has confirmed this to be a problem in the Microsoft Foundation Classes versions 1.0 and 2.0 for MS-DOS and Windows. This problem was corrected in the Microsoft Foundation Classes version 2.0 for Windows NT.
The following code demonstrates this situation. Be sure to link with the correct Microsoft Foundation Classes debugging library.
/*
* Compiler options needed: /D_DEBUG, /D_DOS or /D_WINDOWS
*
/
#include <afx.h>
void main()
{
afxDump << "Hello, world."
<< '\n'; // To fix, comment this line
// << "\n"; // and remove the comment from this line.
}
Keywords : kberrmsg kb16bitonly kbFileIO kbMFC kbVC
Version : 1.0 1.5 7.0
Platform : MS-DOS WINDOWS
Issue type : kbbug
Solution Type : kbfix
Last Reviewed: September 18, 1997