@@ -7315,11 +7315,11 @@ First some bad old code:
7315
7315
7316
7316
Instead use an `enum`:
7317
7317
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 };
7320
7320
7321
7321
int webby = blue; // error: be specific
7322
- Webcolor webby = Webcolor ::blue;
7322
+ Web_color webby = Web_color ::blue;
7323
7323
7324
7324
We used an `enum class` to avoid name clashes.
7325
7325
@@ -7338,20 +7338,20 @@ An enumeration shows the enumerators to be related and can be a named type.
7338
7338
7339
7339
##### Example
7340
7340
7341
- enum class Webcolor { red = 0xFF0000, green = 0x00FF00, blue = 0x0000FF };
7341
+ enum class Web_color { red = 0xFF0000, green = 0x00FF00, blue = 0x0000FF };
7342
7342
7343
7343
7344
7344
##### Note
7345
7345
7346
7346
Switching on an enumeration is common and the compiler can warn against unusual patterns of case labels. For example:
7347
7347
7348
- enum class Productinfo { red = 0, purple = 1, blue = 2 };
7348
+ enum class Product_info { red = 0, purple = 1, blue = 2 };
7349
7349
7350
- void print(Productinfo inf)
7350
+ void print(Product_info inf)
7351
7351
{
7352
7352
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;
7355
7355
}
7356
7356
}
7357
7357
@@ -7371,27 +7371,27 @@ To minimize surprises: traditional enums convert to int too readily.
7371
7371
7372
7372
##### Example
7373
7373
7374
- void PrintColor (int color);
7374
+ void Print_color (int color);
7375
7375
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 };
7378
7378
7379
- Webcolor webby = Webcolor ::blue;
7379
+ Web_color webby = Web_color ::blue;
7380
7380
7381
7381
// 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);
7384
7384
7385
7385
Instead use an `enum class`:
7386
7386
7387
- void PrintColor (int color);
7387
+ void Print_color (int color);
7388
7388
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 };
7391
7391
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.
7395
7395
7396
7396
##### Enforcement
7397
7397
@@ -7436,7 +7436,7 @@ Avoid clashes with macros.
7436
7436
// productinfo.h
7437
7437
// The following define product subtypes based on color
7438
7438
7439
- enum class Productinfo { RED, PURPLE, BLUE }; // syntax error
7439
+ enum class Product_info { RED, PURPLE, BLUE }; // syntax error
7440
7440
7441
7441
##### Enforcement
7442
7442
@@ -7480,7 +7480,7 @@ The default is the easiest to read and write.
7480
7480
enum class Direction : char { n, s, e, w,
7481
7481
ne, nw, se, sw }; // underlying type saves space
7482
7482
7483
- enum class Webcolor : int { red = 0xFF0000,
7483
+ enum class Web_color : int { red = 0xFF0000,
7484
7484
green = 0x00FF00,
7485
7485
blue = 0x0000FF }; // underlying type is redundant
7486
7486
0 commit comments