What is the function of const specifier in enum types?

Thomas
enum foo : const unsigned int
{
    F,
    S,
    T
};

void func()
{
    foo p;
    p = F;
}

The above compiles so the underlying type is not a const type?

songyuanyao

The const qualifier is ignored in the specification of enum-base; which just expects an integral type to be used as the underlying type of the enumeration type, specifying const (or volatile) doesn't make much sense.

(emphasis mine)

colon (:), followed by a type-specifier-seq that names an integral type (if it is cv-qualified, qualifications are ignored) that will serve as the fixed underlying type for this enumeration type

From the standard, [dcl.enum]/2:

(emphasis mine)

The type-specifier-seq of an enum-base shall name an integral type; any cv-qualification is ignored.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

It is possible to overload function by const specifier?

From Dev

It is possible to overload function by const specifier?

From Dev

C what is a function specifier? like _inline _NORETURN

From Dev

What are the allowed types for an enum (class)?

From Dev

What types can be declared as const?

From Dev

What types can be declared as const?

From Dev

looser throw specifier for ‘virtual const char* ro_err::StdErr::what() const’

From Dev

Pass arrays of different types of enum values to a function

From Dev

What is the difference between int const function(parameters), int function(const parameters), and int function(parameters) const?

From Dev

What is the internal logic for Enum HasFlag function implementation

From Dev

What are the expected values for the various "ENUM" types returned by the SurveyMonkey API?

From Java

What is meant with "const" at end of function declaration?

From Dev

C++/ENUM/Type Name/Specifier

From Dev

What's the equivalent of C++ `const` return types in Delphi

From Dev

Is there a way to make a function to accept any Enum types that have a rawValue of String?

From Dev

Can I have function types in Java's Enum like Swift?

From Java

What is the printf format specifier for bool?

From Dev

What is the format specifier for binary in C?

From Dev

What is the following format specifier doing?

From Java

Is it better to remove "const" in front of "primitive" types used as function parameters in the header?

From Dev

Function argument template parameter ambiguous for const ref types

From Dev

scanf() function with different format specifier

From Dev

What are the possible data types for canvas' toDataURL() function?

From Dev

What does it mean to declare a variable with a storage class specifier but no type specifier?

From Dev

What does it mean to declare a variable with a storage class specifier but no type specifier?

From Dev

What is the difference between writing static const uint variable and anonymous enum variable?

From Dev

ENUM and types creation in SQLite

From Dev

Overload using Enum types

From Dev

Working with enum types in java

Related Related

  1. 1

    It is possible to overload function by const specifier?

  2. 2

    It is possible to overload function by const specifier?

  3. 3

    C what is a function specifier? like _inline _NORETURN

  4. 4

    What are the allowed types for an enum (class)?

  5. 5

    What types can be declared as const?

  6. 6

    What types can be declared as const?

  7. 7

    looser throw specifier for ‘virtual const char* ro_err::StdErr::what() const’

  8. 8

    Pass arrays of different types of enum values to a function

  9. 9

    What is the difference between int const function(parameters), int function(const parameters), and int function(parameters) const?

  10. 10

    What is the internal logic for Enum HasFlag function implementation

  11. 11

    What are the expected values for the various "ENUM" types returned by the SurveyMonkey API?

  12. 12

    What is meant with "const" at end of function declaration?

  13. 13

    C++/ENUM/Type Name/Specifier

  14. 14

    What's the equivalent of C++ `const` return types in Delphi

  15. 15

    Is there a way to make a function to accept any Enum types that have a rawValue of String?

  16. 16

    Can I have function types in Java's Enum like Swift?

  17. 17

    What is the printf format specifier for bool?

  18. 18

    What is the format specifier for binary in C?

  19. 19

    What is the following format specifier doing?

  20. 20

    Is it better to remove "const" in front of "primitive" types used as function parameters in the header?

  21. 21

    Function argument template parameter ambiguous for const ref types

  22. 22

    scanf() function with different format specifier

  23. 23

    What are the possible data types for canvas' toDataURL() function?

  24. 24

    What does it mean to declare a variable with a storage class specifier but no type specifier?

  25. 25

    What does it mean to declare a variable with a storage class specifier but no type specifier?

  26. 26

    What is the difference between writing static const uint variable and anonymous enum variable?

  27. 27

    ENUM and types creation in SQLite

  28. 28

    Overload using Enum types

  29. 29

    Working with enum types in java

HotTag

Archive