C++ 中哪些类型是枚举类型? [英] What types in C++ are enumerated types?

查看:33
本文介绍了C++ 中哪些类型是枚举类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现(点击此处)开关可以使用整数类型或C++中控制表达式中的枚举类型".

I found that(click here) switch can use integer types or "enumerated types" in controlling expression inC++.

这篇文章中对枚举"的一种解释是枚举类型 是使用一组自定义标识符(称为枚举数)作为可能值定义的类型".

One explanation for "enumerate" in this article is that enumerated types "are types that are defined with a set of custom identifiers, known as enumerators, as possible values".

然而,对于像 char、int、long、double 这样的类型,由于它们最多只使用 8 个字节,所以它最多包含 232 个可能的元素.那么所有这些可能的元素选择肯定是可排序的(使用常见的算术比较).因此它们都是枚举类型.此外,这个论点也适用于任何其他类型.那么,什么类型不是枚举类型?

However, for types like char, int, long, double, since they only use at most 8 bytes, it contains at most 232 possible elements. Then all these possible choice of elements are definitely sortable (using the common arithmetic comparison). Hence they are all enumerated types. Further, this argument would also apply to any other types. Then, what type is not an enumerated type?

能够解释枚举类型的定义的人会加分,并且对枚举类型非枚举类型都给出具体的例子.

Credit will give to those who can explain the definition of enumerated type clearly, and also give concrete examples on both enumerated types and non-enumerated types.

提前致谢 =)

推荐答案

来自 cppreference:

枚举是一个独特的类型,它的值被限制为以下之一几个显式命名的常量(枚举器").的价值观常量是称为基础类型的整数类型的值的枚举.

An enumeration is a distinct type whose value is restricted to one of several explicitly named constants ("enumerators"). The values of the constants are values of an integral type known as the underlying type of the enumeration.

因此,枚举类型的示例是您可能使用 enum 关键字声明的任何类型.

So an example of an enumerated type is any type you might declare using the enum keyword.

非枚举类型的一个例子是 int 因为它的值不限于一组显式命名的常量,而是所有整数(或所有整数和 int 可以表示给定它的大小).

An example of a non-enumerated type would be an int because its values are not restricted to a set of explicitly named constants, but rather all integers (or all integers an int could represent given its size).

非枚举类型的另一个示例是指向任何内容的指针,因为指针的可能值集不是整数.

Another example of a non-enumerated type is a pointer to anything because the set of possible values for a pointer are not integrals.

这篇关于C++ 中哪些类型是枚举类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆