Knowledge Base

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

Article ID: 149965

Article Last Modified on 7/5/2005


APPLIES TO


This article was previously published under Q149965

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
            }
				

Additional query words: kbVC400bug

Keywords: kbbug kbfix kbvc500fix kbcpponly kbcompiler KB149965