Skip to content

Commit 83974c1

Browse files
authored
「スコープ付き列挙型のusing宣言」のサンプルコードを修正
enum class は整数への暗黙的型変換を提供しておらず、サンプルコードの記載方法ではエラーとなっていたため、キャストを使用する形でエラーの回避を行いました。 参考:https://timsong-cpp.github.io/cppwp/n4861/enum#dcl.enum-10 また、出力の方もコンパイルが成功した場合は「1」となる想定の物が「10」と記載されていたため、同コミットでまとめて修正を行っています。
1 parent 57afeb8 commit 83974c1

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lang/cpp20/using_enum.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,20 @@ int main() {
8181
using enum Enum1;
8282
using enum Enum2::Enum;
8383
using Enum3::Value3;
84-
std::cout << Value1 << std::endl;
84+
std::cout << static_cast<int>(Value1) << std::endl;
8585
std::cout << ::Value1 << std::endl;
8686
std::cout << Value2 << std::endl;
87-
std::cout << Value3 << std::endl;
88-
std::cout << Enum3::Value4 << std::endl;
89-
std::cout << Type::Value4 << std::endl;
90-
std::cout << Type().Value4 << std::endl;
87+
std::cout << static_cast<int>(Value3) << std::endl;
88+
std::cout << static_cast<int>(Enum3::Value4) << std::endl;
89+
std::cout << static_cast<int>(Type::Value4) << std::endl;
90+
std::cout << static_cast<int>(Type().Value4) << std::endl;
9191
}
9292
```
9393
9494
### 出力
9595
```
9696
0
97-
10
97+
1
9898
0
9999
0
100100
1

0 commit comments

Comments
 (0)