Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are enums considered compound types?

Tags:

c++

types

enums

Arrays, functions, pointers, references, classes, unions, enumerations and pointers to members are compound types.

My understanding of a compound type is that is based on other type(s). For example, T[n], T* and T& are all based on T. Then what other type(s) is an enumeration based on?

Or if my understanding of compound types is incorrect, what exactly is it about a type that makes it a compound type? Is compound simply a synonym for user-defined?

like image 534
fredoverflow Avatar asked May 26 '10 22:05

fredoverflow


1 Answers

In C++ enum types are scalar types, yet at the same time they are compound types since they are built on top of some fundamental integral type. In case of an array or pointer you specify "base" type explicitly, but in case of an enum the specific underlying integral type is chosen implicitly and automatically by the implementation. You have no manual control over the underlying integral type, which still doesn't disqualify enum types from being compound in nature.

Some compilers (as well as future C++ standard C++0x) allow user to specify the underlying integer type for given enum type, which makes it more obvious that it is in fact a compound type. See here for examples like

enum class Color : char { red, blue };
like image 179
AnT Avatar answered Oct 08 '22 06:10

AnT