August 2012
Intermediate to advanced
976 pages
30h 17m
English
Because an object of enum type may be initialized only by another object of that enum type or by one of its enumerators (§ 19.3, p. 833), an integral value that happens to have the same value as an enumerator cannot be used to call a function expecting an enum argument:
// unscoped enumeration; the underlying type is machine dependentenum Tokens {INLINE = 128, VIRTUAL = 129};void ff(Tokens);void ff(int);int main() { Tokens curTok = INLINE; ff(128); // exactly matches ff(int) ff(INLINE); // exactly matches ff(Tokens) ff(curTok); // exactly matches ff(Tokens) return 0;}
Although we cannot pass an integral value to an enum parameter, we can pass an object or enumerator of an unscoped enumeration ...
Read now
Unlock full access