<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          C++核心準(zhǔn)則Enum.8:只在必要時指定枚舉值

          e057cd040e532a86854afd36bffc7030.webp

          Enum.8: Specify enumerator values only when necessary

          Enum.8:? 只在必要時指定枚舉值


          Reason(原因)

          It's the simplest. It avoids duplicate enumerator values. The default gives a consecutive set of values that is good for?switch-statement implementations.

          這樣最簡單??梢员苊庵貜?fù)的枚舉值。默認(rèn)的情況會分配一組容易被switch語句使用的連續(xù)值。


          Example(示例)

          enum class Col1 { red, yellow, blue };
          enum class Col2 { red = 1, yellow = 2, blue = 2 }; // typo
          enum class Month { jan = 1, feb, mar, apr, may, jun,
          jul, august, sep, oct, nov, dec }; // starting with 1 is conventional
          enum class Base_flag { dec = 1, oct = dec << 1, hex = dec << 2 }; // set of bits

          Specifying values is necessary to match conventional values (e.g.,?Month) and where consecutive values are undesirable (e.g., to get separate bits as in?Base_flag).

          為了符合日常習(xí)慣(例如月)或者不希望連續(xù)值(例如用于獲取標(biāo)志變量中的特定標(biāo)志位)時有必要定義枚舉值。


          Enforcement(實(shí)施建議)

          • Flag duplicate enumerator values

          • 標(biāo)記重復(fù)的枚舉值

          • Flag explicitly specified all-consecutive enumerator values

          • 標(biāo)記顯式定義所有枚舉值為連續(xù)值情況。


          原文鏈接:

          https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#enum8-specify-enumerator-values-only-when-necessary




          覺得本文有幫助?請分享給更多人。

          關(guān)注【面向?qū)ο笏伎肌枯p松學(xué)習(xí)每一天!

          面向?qū)ο箝_發(fā),面向?qū)ο笏伎迹?/span>

          瀏覽 84
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  国产内射在线观看 | 密桃视频黄片高清无码 | 云南性老太HD大全 | av一级黄片 | 中文AV在线播放 |