FIX: C2668 in Overloaded Function When enum Is Promoted to int

Last reviewed: September 19, 1997
Article ID: Q149965
The information in this article applies to:
  • The Microsoft C/C++ Compiler (CL.EXE) included with: - Microsoft Visual C++ for Windows, versions 1.5, 1.51, 1.52 - Microsoft Visual C++, 32-bit Edition, versions 2.0, 2.1, 2.2, 4.0,

         4.1, 4.2
    

SYMPTOMS

When a function is overloaded to take an int parameter in one instance and an unsigned int in another, the following error results if a call to the function is made with an enumerated type:

   C2668 error: 'func' : ambiguous call to overloaded function (new
   behavior; please see help)

RESOLUTION

  • Use a cast when calling the function, such as func((unsigned)y).

    -or-

  • Overload the function to take the enumerated type, such as:

    func(enum A); func(enum E);

STATUS

Microsoft has confirmed this to be bug in the Microsoft products listed at the beginning of this article. This bug was corrected in Visual C++ version 5.0.

MORE INFORMATION

Sample Code to Demonstrate Problem

   // Compile option needed: none

   enum A{eA = 0, eB};
   enum E{e = -1};

   void func(int a);
   void func(unsigned int a);

   void main(){
              A y = eA;
              E e1 = e;
              int m = 2;

              func(m);        // calls func(int)
              func(y);        // C2668 error
              func(e1);       // C2668 error
            }
Keywords          : CPPIss vcbuglist400 vcfixlist500 kbprg
Version           : 1.5 1.51 1.52 2.0 2.1 2.2 4.0 4.
Platform          : NT 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 19, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.