@@ -7315,11 +7315,11 @@ First some bad old code:
73157315
73167316Instead use an `enum`:
73177317
7318- enum class Webcolor { red = 0xFF0000, green = 0x00FF00, blue = 0x0000FF };
7319- enum class Productinfo { red = 0, purple = 1, blue = 2 };
7318+ enum class Web_color { red = 0xFF0000, green = 0x00FF00, blue = 0x0000FF };
7319+ enum class Product_info { red = 0, purple = 1, blue = 2 };
73207320
73217321 int webby = blue; // error: be specific
7322- Webcolor webby = Webcolor ::blue;
7322+ Web_color webby = Web_color ::blue;
73237323
73247324We used an `enum class` to avoid name clashes.
73257325
@@ -7338,20 +7338,20 @@ An enumeration shows the enumerators to be related and can be a named type.
73387338
73397339##### Example
73407340
7341- enum class Webcolor { red = 0xFF0000, green = 0x00FF00, blue = 0x0000FF };
7341+ enum class Web_color { red = 0xFF0000, green = 0x00FF00, blue = 0x0000FF };
73427342
73437343
73447344##### Note
73457345
73467346Switching on an enumeration is common and the compiler can warn against unusual patterns of case labels. For example:
73477347
7348- enum class Productinfo { red = 0, purple = 1, blue = 2 };
7348+ enum class Product_info { red = 0, purple = 1, blue = 2 };
73497349
7350- void print(Productinfo inf)
7350+ void print(Product_info inf)
73517351 {
73527352 switch (inf) {
7353- case Productinfo ::red: cout << "red"; break;
7354- case Productinfo ::purple: cout << "purple"; break;
7353+ case Product_info ::red: cout << "red"; break;
7354+ case Product_info ::purple: cout << "purple"; break;
73557355 }
73567356 }
73577357
@@ -7371,27 +7371,27 @@ To minimize surprises: traditional enums convert to int too readily.
73717371
73727372##### Example
73737373
7374- void PrintColor (int color);
7374+ void Print_color (int color);
73757375
7376- enum Webcolor { red = 0xFF0000, green = 0x00FF00, blue = 0x0000FF };
7377- enum Productinfo { Red = 0, Purple = 1, Blue = 2 };
7376+ enum Web_color { red = 0xFF0000, green = 0x00FF00, blue = 0x0000FF };
7377+ enum Product_info { Red = 0, Purple = 1, Blue = 2 };
73787378
7379- Webcolor webby = Webcolor ::blue;
7379+ Web_color webby = Web_color ::blue;
73807380
73817381 // Clearly at least one of these calls is buggy.
7382- PrintColor (webby);
7383- PrintColor(Productinfo ::Blue);
7382+ Print_color (webby);
7383+ Print_color(Product_info ::Blue);
73847384
73857385Instead use an `enum class`:
73867386
7387- void PrintColor (int color);
7387+ void Print_color (int color);
73887388
7389- enum class Webcolor { red = 0xFF0000, green = 0x00FF00, blue = 0x0000FF };
7390- enum class Productinfo { red = 0, purple = 1, blue = 2 };
7389+ enum class Web_color { red = 0xFF0000, green = 0x00FF00, blue = 0x0000FF };
7390+ enum class Product_info { red = 0, purple = 1, blue = 2 };
73917391
7392- Webcolor webby = Webcolor ::blue;
7393- PrintColor (webby); // Error: cannot convert Webcolor to int.
7394- PrintColor(Productinfo ::Red); // Error: cannot convert Productinfo to int.
7392+ Web_color webby = Web_color ::blue;
7393+ Print_color (webby); // Error: cannot convert Web_color to int.
7394+ Print_color(Product_info ::Red); // Error: cannot convert Product_info to int.
73957395
73967396##### Enforcement
73977397
@@ -7436,7 +7436,7 @@ Avoid clashes with macros.
74367436 // productinfo.h
74377437 // The following define product subtypes based on color
74387438
7439- enum class Productinfo { RED, PURPLE, BLUE }; // syntax error
7439+ enum class Product_info { RED, PURPLE, BLUE }; // syntax error
74407440
74417441##### Enforcement
74427442
@@ -7480,7 +7480,7 @@ The default is the easiest to read and write.
74807480 enum class Direction : char { n, s, e, w,
74817481 ne, nw, se, sw }; // underlying type saves space
74827482
7483- enum class Webcolor : int { red = 0xFF0000,
7483+ enum class Web_color : int { red = 0xFF0000,
74847484 green = 0x00FF00,
74857485 blue = 0x0000FF }; // underlying type is redundant
74867486
0 commit comments