www.digitalmars.com         C & C++   DMDScript  

c++ - enum: integral promotions

#include <stdio.h>

struct A
{
  void f(int a)
  {
    printf("f(int)\n");
  }

  void f(unsigned int a)
  {
    printf("f(unsigned int)\n");
  }

  void f(long a)
  {
    printf("f(long)\n");
  }
};


int main()
{
  A a;

  enum SignedEnum
  {
    SENUM_1 = 0,
    SENUM_2 = 1
  };

  enum UnsignedEnum
  {
    UENUM_1 = 0,
    UENUM_2 = 0x80000000
  };

  a.f(SENUM_1);
  // Error: ambiguous reference to symbol
  // Had: A::f(int )
  // and: A::f(long )
  a.f(SENUM_2);
  // Error: ambiguous reference to symbol
  // Had: A::f(int )
  // and: A::f(long )

  a.f(UENUM_1);
  // Error: ambiguous reference to symbol
  // Had: A::f(int )
  // and: A::f(long )
  a.f(UENUM_2);
  // Error: ambiguous reference to symbol
  // Had: A::f(int )
  // and: A::f(long )

  return 0;
}


The expected output is:

f(int)
f(int)
f(unsigned int)
f(unsigned int)


See 4.5 Integral promotions [conv.prom], paragraph 2.

It's low priority - just a bit annoying when using IOStreams and enums.


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw jabber.at
mailto cmeerw at web.de

...and what have you contributed to the Net?
Mar 23 2003