mirror of
https://github.com/Light-City/CPlusPlusThings.git
synced 2026-10-28 19:04:45 +08:00
- const README: rewrite the space-saving claim per issue #5 follow-ups (constant-expression const vs #define immediates; which const qualify as constant expressions) - const README: fix the class-section diagnosis per issue #338 (overload resolution picks the const overload; the restriction only surfaces once that overload is removed) - sizeof README: virtual-inheritance result is compiler-dependent (GCC merges vbptr+vfptr -> 16, MSVC keeps them separate -> 32) #246 - static README: new section on internal linkage / access restriction with anonymous-namespace comparison #142 - 10-day practice: full problem list table + fixed day links #136 - new design_pattern/singleton/singleton_default.hpp: reusable thread-safe CRTP singleton template, compile+concurrency tested #303
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
# 从初级到高级的enum那些事
|
||||
> 本文档由 [C++那些事网站](https://light-city.github.io/stories_things/cpp-things/enum/) 同步生成,网站版本含多语言与更新排版。
|
||||
|
||||
# C++ enum 枚举类型
|
||||
|
||||
## 关于作者:
|
||||
|
||||
个人公众号:
|
||||
|
||||

|
||||

|
||||
|
||||
|
||||
## 传统行为
|
||||
@@ -37,7 +39,7 @@ int main()
|
||||
- 会隐式转换为int
|
||||
- 用来表征枚举变量的实际类型不能明确指定,从而无法支持枚举类型的前向声明。
|
||||
|
||||
具体实现见:[tradition_color.cpp](tradition_color.cpp)
|
||||
具体实现见:[tradition_color.cpp](https://github.com/Light-City/CPlusPlusThings/tree/master/basic_content/enum/tradition_color.cpp)
|
||||
|
||||
## 经典做法
|
||||
|
||||
@@ -72,7 +74,7 @@ struct Color1
|
||||
};
|
||||
```
|
||||
|
||||
具体实现见:[classic_practice.cpp](classic_practice.cpp)
|
||||
具体实现见:[classic_practice.cpp](https://github.com/Light-City/CPlusPlusThings/tree/master/basic_content/enum/classic_practice.cpp)
|
||||
|
||||
## C++11 的枚举类
|
||||
|
||||
@@ -110,7 +112,7 @@ enum class Color3:char
|
||||
char c3 = static_cast<char>(Color3::RED);
|
||||
```
|
||||
|
||||
具体实现见:[classic_practice.cpp](classic_practice.cpp)
|
||||
具体实现见:[classic_practice.cpp](https://github.com/Light-City/CPlusPlusThings/tree/master/basic_content/enum/classic_practice.cpp)
|
||||
|
||||
## 类中的枚举类型
|
||||
|
||||
@@ -161,4 +163,4 @@ public:
|
||||
|
||||
枚举常量不会占用对象的存储空间,它们在编译时被全部求值。
|
||||
|
||||
枚举常量的缺点是:它的隐含数据类型是整数,其最大值有限,且不能表示浮点。
|
||||
枚举常量的缺点是:它的隐含数据类型是整数,其最大值有限,且不能表示浮点。
|
||||
Reference in New Issue
Block a user