0

I am looking at some code, and see assignment of an enum to a varaible.

Let's just say x = y; where y is an enum.

Except that it actually says x = { y } ;. My C++ is a little rusty (too much Ada). Are those braces actually required? If so, why? I believe the code to be C++ 11 or 14.

east1000
  • 1,240
  • 1
  • 10
  • 30
Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551
  • 1
    Is `y` a plain-old `enum`, or an `enum class`? – Bathsheba Sep 30 '21 at 08:26
  • 1
    [Why is list initialization (using curly braces) better than the alternatives?](https://stackoverflow.com/q/18222926/995714), [C++: Variable initialization using `x{0}`](https://stackoverflow.com/q/20392537/995714) – phuclv Sep 30 '21 at 08:40
  • 5
    You say a lot about `y`, yet little to nothing about `x`, which is equally as important here. – StoryTeller - Unslander Monica Sep 30 '21 at 08:42
  • 1
    Hour long presentation [The Nightmare of Initialization in C++](https://www.youtube.com/watch?v=7DTlWPgX6zs) by Nicolai Josuttis at CppCon 2018. – Eljay Sep 30 '21 at 11:32
  • @StoryTeller-UnslanderMonica it is astructriue ember of the same type as the enum being assigned to it. I ought to have mentioned that the code compiles & Lints warning free – Mawg says reinstate Monica Sep 30 '21 at 12:28

0 Answers0