On Wed, 14 Nov 2018 00:43:54 +0000, Rubn wrote: > I wonder what these examples are? What did C++ do instead, cause > something tells me it didn't do what D is doing. An enum in C++ doesn't > call different function overloads based on the constant value.
Long long and unsigned long long give an ambiguous overload error. Unsigned int uses the unsigned int overload. Everything else uses the int overload. Test code: ``` #include <iostream> #include <climits> using namespace std; void foo(bool c) { cout << "bool " << c << endl; } void foo(unsigned char c) { cout << "unsigned char " << c << endl; } void foo(char c) { cout << "char " << c << endl; } void foo(int c) { cout << "int " << c << endl; } void foo(unsigned int c) { cout << "unsigned int " << c << endl; } void foo(long long c) { cout << "long long " << c << endl; } void foo(unsigned long long c) { cout << "unsigned long long " << c << endl; } enum Bool : bool { b = 1 }; enum Char : char { c = CHAR_MAX }; enum UChar : unsigned char { d = UCHAR_MAX }; enum Short : short { e = SHRT_MAX }; enum UShort : unsigned short { f = USHRT_MAX }; enum Int : int { g = INT_MAX }; enum UInt : unsigned int { h = UINT_MAX }; enum LongLong : long long { i = LLONG_MAX }; enum ULongLong : unsigned long long { j = ULLONG_MAX }; int main(int argc, char** argv) { foo(b); foo(c); foo(d); foo(e); foo(f); foo(g); foo(h); //foo(i); //foo(j); } ``` Output: int 1 int 127 int 255 int 32767 int 65535 int 2147483647 unsigned int 4294967295