FIX: C2593: "operato

Last reviewed: September 16, 1997
Article ID: Q87640

The information in this article applies to:
  • The Microsoft Foundation Classes (MFC), included with:

        - Microsoft C/C++, version 7.0
        - Microsoft Visual C++ for Windows, versions 1.0, 1.5
    

SYMPTOMS

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

CAUSE

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);

RESOLUTION

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 *);

STATUS

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.

MORE INFORMATION

The following code demonstrates this situation. Be sure to link with the correct Microsoft Foundation Classes debugging library.

Sample Code

   /*
    * 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          : kb16bitonly MfcFileIO kberrmsg
Technology        : kbmfc
Version           : 1.0 1.5 7.0
Platform          : MS-DOS WINDOWS
Issue type        : kbbug
Solution Type     : kbfix


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 16, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.