{"id":5350,"date":"2017-11-24T20:59:36","date_gmt":"2017-11-24T20:59:36","guid":{"rendered":"https:\/\/www.modernescpp.com\/index.php\/c-core-guidelines-rules-for-enumerations\/"},"modified":"2023-06-26T12:01:32","modified_gmt":"2023-06-26T12:01:32","slug":"c-core-guidelines-rules-for-enumerations","status":"publish","type":"post","link":"https:\/\/www.modernescpp.com\/index.php\/c-core-guidelines-rules-for-enumerations\/","title":{"rendered":"C++ Core Guidelines: Rules for Enumerations"},"content":{"rendered":"<p>The section to enumerations has eight rules. Since C++11, we have scoped enumerations which overcome a lot of the drawbacks of classical enumerations.&nbsp;<\/p>\n<p><!--more--><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-5349\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2017\/11\/hand-162127_640.png\" alt=\"hand 162127 640\" width=\"640\" height=\"320\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2017\/11\/hand-162127_640.png 640w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2017\/11\/hand-162127_640-300x150.png 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>Enumerations are sets of integer values which behave like a type. Here is the summary of the rules:<\/p>\n<ul>\n<li><a href=\"http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Renum-macro\">Enum.1: Prefer enumerations over macros<\/a><\/li>\n<li><a href=\"http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Renum-set\">Enum.2: Use enumerations to represent sets of related named constants<\/a><\/li>\n<li><a href=\"http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Renum-class\">Enum.3: Prefer <code class=\"highlighter-rouge no-highlight\">enum class<\/code>es over \u201cplain\u201d <code class=\"highlighter-rouge no-highlight\">enum<\/code>s<\/a><\/li>\n<li><a href=\"http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Renum-oper\">Enum.4: Define operations on enumerations for safe and simple use<\/a><\/li>\n<li><a href=\"http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Renum-caps\">Enum.5: Don\u2019t use <code class=\"highlighter-rouge no-highlight\">ALL_CAPS<\/code> for enumerators<\/a><\/li>\n<li><a href=\"http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Renum-unnamed\">Enum.6: Avoid unnamed enumerations<\/a><\/li>\n<li><a href=\"http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Renum-underlying\">Enum.7: Specify the underlying type of an enumeration only when necessary<\/a><\/li>\n<li><a href=\"http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Renum-value\">Enum.8: Specify enumerator values only when necessary<\/a><\/li>\n<\/ul>\n<p>As I mentioned in the opening of this post: classical enumerations have a lot of drawbacks. Let me explicitly compare classical (unscoped) enumerations and scoped enumerations (sometimes called strongly-typed enumerations) because this important comparison is not explicitly described in the rules.<\/p>\n<p>Here is a classical enumeration:<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #006699; font-weight: bold;\">enum<\/span> Colour{\r\n  red,\r\n  blue,\r\n  green\r\n};\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>Here are the drawbacks of the classical enumerations:<\/p>\n<ul>\n<li>The enumerators have no scope<\/li>\n<li>The enumerators implicitly convert to <span style=\"font-family: courier new,courier;\">int<\/span><\/li>\n<li>The enumerators pollute the global namespace<\/li>\n<li>The type of enumerator is not defined. It just has to be big enough to hold the enumerator.<\/li>\n<\/ul>\n<p>By using the keyword <span style=\"font-family: courier new,courier;\">class<\/span> or <span style=\"font-family: courier new,courier;\">struct,<\/span> the classical enumeration becomes a scoped enumeration (enum class):<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #006699; font-weight: bold;\">enum class<\/span> ColourScoped{\r\n  red,\r\n  blue,\r\n  green\r\n};\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>Now, you must use the scope operator to access the enumerators: <span style=\"font-family: courier new,courier;\">ColourScoped::red. ColourScoped::red <\/span>will not implicitly convert to <span style=\"font-family: courier new,courier;\">int<\/span> and will not pollute the global namespace. Additionally, the underlying type is per default<span style=\"font-family: courier new,courier;\"> int.&nbsp;<\/span><\/p>\n<p>After providing the background information, we can directly jump into the rules.<span style=\"font-family: courier new,courier;\"> <\/span><\/p>\n<h3><a href=\"http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Renum-macro\">Enum.1: Prefer enumerations over macros<\/a><\/h3>\n<p>Macros don&#8217;t respect scope and have no type. This means you can override a previously set macro that specifies a color.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #0099ff; font-style: italic;\">\/\/ webcolors.h <\/span>\r\n<span style=\"color: #009999;\">#define RED   0xFF0000<\/span>\r\n\r\n<span style=\"color: #0099ff; font-style: italic;\">\/\/ productinfo.h<\/span>\r\n<span style=\"color: #009999;\">#define RED    0<\/span>\r\n\r\n<span style=\"color: #007788; font-weight: bold;\">int<\/span> webcolor <span style=\"color: #555555;\">=<\/span> RED;   <span style=\"color: #0099ff; font-style: italic;\">\/\/ should be 0xFF0000<\/span>\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>With <span style=\"font-family: courier new,courier;\">ColourScoped<\/span>, this will not happen because you have to use the scope operator: C<span style=\"font-family: courier new,courier;\">olourScoped webcolour = ColourScoped::red;<\/span><\/p>\n<\/p>\n<h3><a href=\"http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Renum-set\">Enum.2: Use enumerations to represent sets of related named constants<\/a><\/h3>\n<p>This rule is quite evident because the enumerators are a set of integers that create a type. &nbsp;<\/p>\n<h3><a href=\"http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Renum-class\">Enum.3: Prefer <code class=\"highlighter-rouge no-highlight\">enum class<\/code>es over \u201cplain\u201d <code class=\"highlighter-rouge no-highlight\">enum<\/code>s<\/a><\/h3>\n<p>The enumerators of a scoped enum (enum class) will not automatically convert to <span style=\"font-family: courier new,courier;\">int<\/span>. You have to access them with the scope operator.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #0099ff; font-style: italic;\">\/\/ scopedEnum.cpp<\/span>\r\n\r\n<span style=\"color: #009999;\">#include &lt;iostream&gt;<\/span>\r\n\r\n<span style=\"color: #006699; font-weight: bold;\">enum<\/span> <span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">ColourScoped<\/span>{\r\n  red,\r\n  blue,\r\n  green\r\n};\r\n\r\n<span style=\"color: #007788; font-weight: bold;\">void<\/span> <span style=\"color: #cc00ff;\">useMe<\/span>(ColourScoped color){\r\n\r\n  <span style=\"color: #006699; font-weight: bold;\">switch<\/span>(color){\r\n  <span style=\"color: #006699; font-weight: bold;\">case<\/span> ColourScoped:<span style=\"color: #555555;\">:<\/span>red<span style=\"color: #555555;\">:<\/span>\r\n    std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"ColourScoped::red\"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;\r\n    <span style=\"color: #006699; font-weight: bold;\">break<\/span>;\r\n  <span style=\"color: #006699; font-weight: bold;\">case<\/span> ColourScoped:<span style=\"color: #555555;\">:<\/span>blue<span style=\"color: #555555;\">:<\/span>\r\n    std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"ColourScoped::blue\"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;\r\n    <span style=\"color: #006699; font-weight: bold;\">break<\/span>;\r\n  <span style=\"color: #006699; font-weight: bold;\">case<\/span> ColourScoped:<span style=\"color: #555555;\">:<\/span>green<span style=\"color: #555555;\">:<\/span>\r\n    std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"ColourScoped::green\"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;\r\n    <span style=\"color: #006699; font-weight: bold;\">break<\/span>;\r\n  }\r\n}\r\n\r\n<span style=\"color: #007788; font-weight: bold;\">int<\/span> <span style=\"color: #cc00ff;\">main<\/span>(){\r\n\r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span>  <span style=\"color: #006699; font-weight: bold;\">static_cast<\/span><span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">int<\/span><span style=\"color: #555555;\">&gt;<\/span>(ColourScoped<span style=\"color: #555555;\">::<\/span>red) <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;   <span style=\"color: #0099ff; font-style: italic;\">\/\/ 0<\/span>\r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span>  <span style=\"color: #006699; font-weight: bold;\">static_cast<\/span><span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">int<\/span><span style=\"color: #555555;\">&gt;<\/span>(ColourScoped<span style=\"color: #555555;\">::<\/span>red) <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;   <span style=\"color: #0099ff; font-style: italic;\">\/\/ 0<\/span>\r\n\r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;\r\n\r\n  ColourScoped colour{ColourScoped<span style=\"color: #555555;\">::<\/span>red};\r\n  useMe(colour);                                                     <span style=\"color: #0099ff; font-style: italic;\">\/\/ ColourScoped::red<\/span>\r\n\r\n}\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<h3><a href=\"http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Renum-oper\">Enum.4: Define operations on enumerations for safe and simple use<\/a><\/h3>\n<p>The rules define an enumeration <span style=\"font-family: courier new,courier;\">Day<\/span> that supports the increment operation.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #006699; font-weight: bold;\">enum<\/span> Day { mon, tue, wed, thu, fri, sat, sun };\r\n\r\nDay<span style=\"color: #555555;\">&amp;<\/span> <span style=\"color: #006699; font-weight: bold;\">operator<\/span><span style=\"color: #555555;\">++<\/span>(Day<span style=\"color: #555555;\">&amp;<\/span> d)\r\n{\r\n    <span style=\"color: #006699; font-weight: bold;\">return<\/span> d <span style=\"color: #555555;\">=<\/span> (d <span style=\"color: #555555;\">==<\/span> Day<span style=\"color: #555555;\">::<\/span>sun) <span style=\"color: #555555;\">?<\/span> Day<span style=\"color: #555555;\">::<\/span>mon <span style=\"color: #555555;\">:<\/span> <span style=\"color: #006699; font-weight: bold;\">static_cast<\/span><span style=\"color: #555555;\">&lt;<\/span>Day<span style=\"color: #555555;\">&gt;<\/span>(<span style=\"color: #006699; font-weight: bold;\">static_cast<\/span><span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">int<\/span><span style=\"color: #555555;\">&gt;<\/span>(d)<span style=\"color: #555555;\">+<\/span><span style=\"color: #ff6600;\">1<\/span>);\r\n}\r\n\r\nDay today <span style=\"color: #555555;\">=<\/span> Day<span style=\"color: #555555;\">::<\/span>sat;\r\nDay tomorrow <span style=\"color: #555555;\">=<\/span> <span style=\"color: #555555;\">++<\/span>today;\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>The<span style=\"font-family: courier new,courier;\"> static_cast<\/span> is necessary in this example because applying the increment operator inside the increment operator would cause an infinite recursion:<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\">Day<span style=\"color: #555555;\">&amp;<\/span> <span style=\"color: #006699; font-weight: bold;\">operator<\/span><span style=\"color: #555555;\">++<\/span>(Day<span style=\"color: #555555;\">&amp;<\/span> d)\r\n{\r\n    <span style=\"color: #006699; font-weight: bold;\">return<\/span> d <span style=\"color: #555555;\">=<\/span> (d <span style=\"color: #555555;\">==<\/span> Day<span style=\"color: #555555;\">::<\/span>sun) <span style=\"color: #555555;\">?<\/span> Day<span style=\"color: #555555;\">::<\/span>mon <span style=\"color: #555555;\">:<\/span> Day{<span style=\"color: #555555;\">++<\/span>d};    <span style=\"color: #0099ff; font-style: italic;\">\/\/ error<\/span>\r\n}\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<h3><a href=\"http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Renum-caps\">Enum.5: Don\u2019t use <code class=\"highlighter-rouge no-highlight\">ALL_CAPS<\/code> for enumerators<\/a><\/h3>\n<p>If you use ALL_CAPS for enumerators, you may get a conflict with macros because they are typically written in ALL_CAPS.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #009999;\">#define RED 0xFF0000<\/span>\r\n\r\n<span style=\"color: #006699; font-weight: bold;\">enum<\/span> <span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">ColourScoped<\/span>{ RED };  <span style=\"color: #0099ff; font-style: italic;\">\/\/ error<\/span>\r\n<\/pre>\n<\/div>\n<h3><a href=\"http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Renum-unnamed\">Enum.6: Avoid unnamed enumerations<\/a><\/h3>\n<p>If you can&#8217;t find a name for the enumerations, the enumerations maybe not be related. In this case, you should use a constexpr value.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #0099ff; font-style: italic;\">\/\/ bad<\/span>\r\n<span style=\"color: #006699; font-weight: bold;\">enum<\/span> { red <span style=\"color: #555555;\">=<\/span> <span style=\"color: #ff6600;\">0xFF0000<\/span>, scale <span style=\"color: #555555;\">=<\/span> <span style=\"color: #ff6600;\">4<\/span>, is_signed <span style=\"color: #555555;\">=<\/span> <span style=\"color: #ff6600;\">1<\/span> };\r\n\r\n<span style=\"color: #0099ff; font-style: italic;\">\/\/ good<\/span>\r\nconstexpr <span style=\"color: #007788; font-weight: bold;\">int<\/span> red <span style=\"color: #555555;\">=<\/span> <span style=\"color: #ff6600;\">0xFF0000<\/span>;\r\nconstexpr <span style=\"color: #007788; font-weight: bold;\">short<\/span> scale <span style=\"color: #555555;\">=<\/span> <span style=\"color: #ff6600;\">4<\/span>;\r\nconstexpr <span style=\"color: #007788; font-weight: bold;\">bool<\/span> is_signed <span style=\"color: #555555;\">=<\/span> <span style=\"color: #336666;\">true<\/span>;\r\n<\/pre>\n<\/div>\n<h3><a href=\"http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Renum-underlying\">Enum.7: Specify the underlying type of an enumeration only when necessary<\/a><\/h3>\n<p>Since C++11, you can specify the underlying type of enumeration and save memory. Per default, the type of a scoped enum is <span style=\"font-family: courier new,courier;\">int<\/span> and, therefore, you can forward declare an enum.<span style=\"font-family: courier new,courier;\"> <\/span><\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #0099ff; font-style: italic;\">\/\/ typeEnum.cpp<\/span>\r\n\r\n<span style=\"color: #009999;\">#include &lt;iostream&gt;<\/span>\r\n\r\n<span style=\"color: #006699; font-weight: bold;\">enum<\/span> <span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">Colour1<\/span>{\r\n  red,\r\n  blue,\r\n  green\r\n};\r\n \r\n<span style=\"color: #006699; font-weight: bold;\">enum<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> Colour2<span style=\"color: #555555;\">:<\/span> <span style=\"color: #007788; font-weight: bold;\">char<\/span> {\r\n  red,\r\n  blue,\r\n  green\r\n};\r\n\r\n<span style=\"color: #007788; font-weight: bold;\">int<\/span> <span style=\"color: #cc00ff;\">main<\/span>(){\r\n\r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #006699; font-weight: bold;\">sizeof<\/span>(Colour1) <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;  <span style=\"color: #0099ff; font-style: italic;\">\/\/ 4<\/span>\r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #006699; font-weight: bold;\">sizeof<\/span>(Colour2) <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;  <span style=\"color: #0099ff; font-style: italic;\">\/\/ 1<\/span>\r\n\r\n}\r\n<\/pre>\n<\/div>\n<h3><a href=\"http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Renum-value\">Enum.8: Specify enumerator values only when necessary<\/a><\/h3>\n<p>By specifying the enumerator values, you may set a value twice. The following enumeration <span style=\"font-family: courier new,courier;\">Col2<\/span> has this issue.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #006699; font-weight: bold;\">enum<\/span> <span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">Col1<\/span> { red, yellow, blue };\r\n<span style=\"color: #006699; font-weight: bold;\">enum<\/span> <span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">Col2<\/span> { red <span style=\"color: #555555;\">=<\/span> <span style=\"color: #ff6600;\">1<\/span>, yellow <span style=\"color: #555555;\">=<\/span> <span style=\"color: #ff6600;\">2<\/span>, blue <span style=\"color: #555555;\">=<\/span> <span style=\"color: #ff6600;\">2<\/span> };    <span style=\"color: #0099ff; font-style: italic;\">\/\/ typo<\/span>\r\n<span style=\"color: #006699; font-weight: bold;\">enum<\/span> <span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">Month<\/span> { jan <span style=\"color: #555555;\">=<\/span> <span style=\"color: #ff6600;\">1<\/span>, feb, mar, apr, may, jun,\r\n                   jul, august, sep, oct, nov, dec }; <span style=\"color: #0099ff; font-style: italic;\">\/\/ starting with 1 is conventional<\/span>\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<h2>What&#8217;s next?<\/h2>\n<p>I made it relatively short in this post. The meta-rule you should keep in mind is: <strong>use scoped enums<\/strong>.<\/p>\n<p>The next section of the C++ core guidelines deals with about 35 rules for resource management. This means we dive into the <a href=\"https:\/\/goo.gl\/uBFnwz\">next post <\/a>right into the heart of C++.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The section to enumerations has eight rules. Since C++11, we have scoped enumerations which overcome a lot of the drawbacks of classical enumerations.&nbsp;<\/p>\n","protected":false},"author":21,"featured_media":5349,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[372],"tags":[458],"class_list":["post-5350","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-modern-c","tag-enum"],"_links":{"self":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/5350","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/comments?post=5350"}],"version-history":[{"count":1,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/5350\/revisions"}],"predecessor-version":[{"id":6850,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/5350\/revisions\/6850"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media\/5349"}],"wp:attachment":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media?parent=5350"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/categories?post=5350"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/tags?post=5350"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}