1 00:00:00,000 --> 00:00:02,190 (soft music) 2 00:00:02,190 --> 00:00:03,023 (air wooshing) 3 00:00:03,023 --> 00:00:05,340 (keyboard clicking) 4 00:00:05,340 --> 00:00:06,173 Frank: Hello everyone. 5 00:00:06,173 --> 00:00:09,750 In the last video we learned about unscoped enumerations. 6 00:00:09,750 --> 00:00:13,320 That is enumerations whose enumerators are unqualified 7 00:00:13,320 --> 00:00:14,250 and they are visible 8 00:00:14,250 --> 00:00:17,670 throughout the scope in which the enumerator was declared. 9 00:00:17,670 --> 00:00:18,750 In this video, we'll learn 10 00:00:18,750 --> 00:00:22,050 about the other side of the coin, scoped enumerations. 11 00:00:22,050 --> 00:00:26,160 That is enumerations whose enumerators are qualified 12 00:00:26,160 --> 00:00:27,720 and therefore they're only visible 13 00:00:27,720 --> 00:00:30,093 by using the scope resolution operator. 14 00:00:30,930 --> 00:00:31,763 This means that 15 00:00:31,763 --> 00:00:34,560 if we want to access an enumeration's enumerators, 16 00:00:34,560 --> 00:00:38,223 we must specify which enumeration the enumerator belongs to. 17 00:00:39,150 --> 00:00:42,030 In place of the singular enum keyword used to 18 00:00:42,030 --> 00:00:44,280 declare unscoped enumerations, 19 00:00:44,280 --> 00:00:49,280 we declare scoped enumerations using the enum class key. 20 00:00:49,380 --> 00:00:51,390 We can also use enum struct 21 00:00:51,390 --> 00:00:54,390 and they are both semantically equivalent. 22 00:00:54,390 --> 00:00:56,190 So you're probably wondering why do we even 23 00:00:56,190 --> 00:00:58,308 need scoped enumerations? 24 00:00:58,308 --> 00:00:59,550 Well, you may remember me saying 25 00:00:59,550 --> 00:01:01,830 that unscoped enumerations can sometimes 26 00:01:01,830 --> 00:01:04,170 cause issues that can only be resolved 27 00:01:04,170 --> 00:01:05,850 by using scope enumerations. 28 00:01:05,850 --> 00:01:06,900 So let's take a look 29 00:01:06,900 --> 00:01:10,143 at two motivating examples so you can understand why. 30 00:01:12,510 --> 00:01:15,840 Here we can see two unscoped enumerations. 31 00:01:15,840 --> 00:01:19,200 The first one contains species of whales 32 00:01:19,200 --> 00:01:21,480 and the other species of sharks. 33 00:01:21,480 --> 00:01:23,040 Now suppose we want to determine 34 00:01:23,040 --> 00:01:26,703 whether a beluga whale is equivalent to a hammerhead shark. 35 00:01:28,020 --> 00:01:30,810 Because both enumerations are unscoped, 36 00:01:30,810 --> 00:01:32,640 this is a valid comparison. 37 00:01:32,640 --> 00:01:35,340 And even worse, it'll evaluate to true 38 00:01:35,340 --> 00:01:38,190 since both enumerators have the same underlying value 39 00:01:38,190 --> 00:01:39,300 of one. 40 00:01:39,300 --> 00:01:41,160 Obviously this is not what we want 41 00:01:41,160 --> 00:01:43,650 since a beluga whale is certainly not equivalent 42 00:01:43,650 --> 00:01:45,660 to a hammerhead shark. 43 00:01:45,660 --> 00:01:47,100 Another issue that can arise 44 00:01:47,100 --> 00:01:50,973 from the use of unscoped enumerations are name clashes. 45 00:01:52,710 --> 00:01:55,590 Suppose that we want to include the blue shark species 46 00:01:55,590 --> 00:01:57,540 in our shark enumeration. 47 00:01:57,540 --> 00:01:59,880 You'll notice that it has the same enumerator name 48 00:01:59,880 --> 00:02:01,770 as the blue whale species, 49 00:02:01,770 --> 00:02:04,260 because both enumerations are unscoped, 50 00:02:04,260 --> 00:02:05,610 the compiler will think we're trying 51 00:02:05,610 --> 00:02:07,710 to redeclare the enumerator blue 52 00:02:07,710 --> 00:02:09,990 and it will generate an error. 53 00:02:09,990 --> 00:02:12,060 Of course, we could just rename the enumerator 54 00:02:12,060 --> 00:02:13,710 to something more specific, 55 00:02:13,710 --> 00:02:15,870 but in general we don't want to have to worry 56 00:02:15,870 --> 00:02:17,820 about naming our enumerators. 57 00:02:17,820 --> 00:02:20,760 So what can we do to address this issue? 58 00:02:20,760 --> 00:02:22,230 As you've probably already guessed, 59 00:02:22,230 --> 00:02:25,567 we can declare the enumerations as scoped enumerations. 60 00:02:27,240 --> 00:02:29,070 The use of if and switch statements 61 00:02:29,070 --> 00:02:33,180 with scoped enumerations is identical to that of unscoped 62 00:02:33,180 --> 00:02:34,710 but with the additional requirement 63 00:02:34,710 --> 00:02:37,530 of specifying enumerator scopes. 64 00:02:37,530 --> 00:02:39,270 In fact, everything you can do 65 00:02:39,270 --> 00:02:40,830 with an unscoped enumeration, 66 00:02:40,830 --> 00:02:42,780 you can do with a scoped enumeration 67 00:02:42,780 --> 00:02:45,840 so long as you specify the scope of its enumerators. 68 00:02:45,840 --> 00:02:46,740 With that said, 69 00:02:46,740 --> 00:02:49,263 there is one difference that's worth discussing. 70 00:02:51,690 --> 00:02:54,330 In this example, we have a scoped enumeration type 71 00:02:54,330 --> 00:02:56,670 named item that might be items 72 00:02:56,670 --> 00:02:58,890 in a grocery or shopping list. 73 00:02:58,890 --> 00:03:02,310 The value of each item might be an item code 74 00:03:02,310 --> 00:03:05,940 or some other value that makes sense in our application. 75 00:03:05,940 --> 00:03:08,490 You'll remember that with unscoped enumerations, 76 00:03:08,490 --> 00:03:10,920 if we wanted to use their enumerator values, 77 00:03:10,920 --> 00:03:12,750 we simply stated the name of the enumerator 78 00:03:12,750 --> 00:03:14,190 and the compiler would implicitly 79 00:03:14,190 --> 00:03:17,430 convert its value to its underlying type. 80 00:03:17,430 --> 00:03:20,580 With scoped enumerations that's not possible. 81 00:03:20,580 --> 00:03:22,560 In fact, if we try to do so, 82 00:03:22,560 --> 00:03:24,870 even with specifying the enumerator scope, 83 00:03:24,870 --> 00:03:26,670 the compiler will generate an error. 84 00:03:28,230 --> 00:03:31,290 This is because scoped enumeration type variables 85 00:03:31,290 --> 00:03:33,810 are not implicitly convertible. 86 00:03:33,810 --> 00:03:35,610 Instead, we must explicitly 87 00:03:35,610 --> 00:03:38,133 cast a variable to its underlying type. 88 00:03:39,060 --> 00:03:40,170 Here you can see that we can 89 00:03:40,170 --> 00:03:43,050 cast the enumerator to the integer underlying type 90 00:03:43,050 --> 00:03:46,050 using a few different styles of casting. 91 00:03:46,050 --> 00:03:47,820 Only then can we use the value 92 00:03:47,820 --> 00:03:49,863 of a scoped enumeration type variable. 93 00:03:51,120 --> 00:03:53,280 Now that we've seen what scoped enumerations are 94 00:03:53,280 --> 00:03:54,690 and how to use them, let's head 95 00:03:54,690 --> 00:03:57,153 on over to the IDE and see a few examples. 96 00:04:00,030 --> 00:04:04,470 Okay, so I'm in the IDE, I'm in the enumerations workspace 97 00:04:04,470 --> 00:04:08,130 and in the Scoped Enums project. 98 00:04:08,130 --> 00:04:09,840 I'm going to close this workspace 99 00:04:09,840 --> 00:04:13,080 for you just to give myself a little bit more room here. 100 00:04:13,080 --> 00:04:16,140 Alright, so what we've got here is just two test examples 101 00:04:16,140 --> 00:04:19,860 that show you different ways to use scoped enumerations. 102 00:04:19,860 --> 00:04:21,899 So I've got them both set up 103 00:04:21,899 --> 00:04:24,240 and I've already built and run the program, 104 00:04:24,240 --> 00:04:25,770 you can see it over here on the right. 105 00:04:25,770 --> 00:04:26,880 And what I want to do is go 106 00:04:26,880 --> 00:04:30,810 over those examples so you can see exactly what's happening. 107 00:04:30,810 --> 00:04:33,960 This first test is very, very similar 108 00:04:33,960 --> 00:04:35,640 to the same first test that we did 109 00:04:35,640 --> 00:04:38,370 in the unscoped enumerations project. 110 00:04:38,370 --> 00:04:42,060 Here we've got our grocery item enumeration. 111 00:04:42,060 --> 00:04:45,480 Now notice that this is now a scoped enumeration 112 00:04:45,480 --> 00:04:47,760 because we're using enum class. 113 00:04:47,760 --> 00:04:49,290 Here I've got milk, bread, apple, 114 00:04:49,290 --> 00:04:51,510 and orange, just like before. 115 00:04:51,510 --> 00:04:54,660 The difference is I've assigned some initializer values 116 00:04:54,660 --> 00:04:56,400 to these enumerators. 117 00:04:56,400 --> 00:04:58,530 And this could represent the item code 118 00:04:58,530 --> 00:05:01,020 or really just about anything you can think of 119 00:05:01,020 --> 00:05:04,530 that could identify the values for these enumerators. 120 00:05:04,530 --> 00:05:07,433 So in this case, we are explicitly defining those values 121 00:05:07,433 --> 00:05:11,520 and the compiler will not generate 0, 1, 2, and 3. 122 00:05:11,520 --> 00:05:13,380 We're going do exactly what we did before 123 00:05:13,380 --> 00:05:15,150 with maybe a little bit of a change. 124 00:05:15,150 --> 00:05:17,700 Okay, so look at some of the examples we've written here. 125 00:05:17,700 --> 00:05:20,370 Here we're overloading the insertion operator again, 126 00:05:20,370 --> 00:05:23,280 the stream insertion operator, just like we did before. 127 00:05:23,280 --> 00:05:25,650 The only real difference is that now, 128 00:05:25,650 --> 00:05:29,280 in order to use those enumerators, we must scope them. 129 00:05:29,280 --> 00:05:33,690 We have to use the enumeration class name, grocery item, 130 00:05:33,690 --> 00:05:35,670 right before the enumerator value 131 00:05:35,670 --> 00:05:37,860 otherwise it's not going to compile. 132 00:05:37,860 --> 00:05:41,700 So that's one of the benefits of using scoped enumerators. 133 00:05:41,700 --> 00:05:43,320 The other thing we're going to do is, 134 00:05:43,320 --> 00:05:45,930 in this case, I'm grabbing the underlying type 135 00:05:45,930 --> 00:05:48,300 of that grocery item value right here, 136 00:05:48,300 --> 00:05:50,070 so all I'm doing is displaying that. 137 00:05:50,070 --> 00:05:52,860 So when we display these values, we're going to display, 138 00:05:52,860 --> 00:05:57,210 you can see up here, apple 132, milk 350 and so forth. 139 00:05:57,210 --> 00:05:58,530 What we're going to do is I'm going to switch 140 00:05:58,530 --> 00:06:01,020 off the grocery item passed into me. 141 00:06:01,020 --> 00:06:04,140 I'm going to put whatever string is appropriate 142 00:06:04,140 --> 00:06:05,640 on the output stream, 143 00:06:05,640 --> 00:06:08,310 and then I'm just going to display the value right 144 00:06:08,310 --> 00:06:09,750 after that colon. 145 00:06:09,750 --> 00:06:12,720 And the value again is one of these guys. 146 00:06:12,720 --> 00:06:15,390 Those are the ones I'm grabbing from the underlying type. 147 00:06:15,390 --> 00:06:17,400 I've got the Boolean function again, 148 00:06:17,400 --> 00:06:20,970 exactly like it was in the previous example with unscoped, 149 00:06:20,970 --> 00:06:23,700 except since it's a scoped enumeration, 150 00:06:23,700 --> 00:06:26,490 we need to qualify those enumerators. 151 00:06:26,490 --> 00:06:27,330 So in this case, 152 00:06:27,330 --> 00:06:30,240 whatever grocery item is passed into this function, 153 00:06:30,240 --> 00:06:33,240 if it's one of these four, then we know it's valid 154 00:06:33,240 --> 00:06:36,270 otherwise we'll return false because it's invalid. 155 00:06:36,270 --> 00:06:38,700 And then the display grocery list function 156 00:06:38,700 --> 00:06:41,280 that I wrote is exactly the same again, 157 00:06:41,280 --> 00:06:43,980 the whole point of this was to create an unscoped version 158 00:06:43,980 --> 00:06:46,320 and a scoped version so you could see the difference. 159 00:06:46,320 --> 00:06:48,720 So in this case, we've got that std::vector 160 00:06:48,720 --> 00:06:51,330 of grocery items just like we did before. 161 00:06:51,330 --> 00:06:53,880 And we're going to loop through that using the range based 162 00:06:53,880 --> 00:06:57,600 for loop right here on line 64 and just display them. 163 00:06:57,600 --> 00:06:58,710 So that's pretty simple. 164 00:06:58,710 --> 00:07:00,990 We'll keep track of what's valid and invalid. 165 00:07:00,990 --> 00:07:03,480 I went over this in more detail in the unscoped video, 166 00:07:03,480 --> 00:07:04,950 so you can check it out there. 167 00:07:04,950 --> 00:07:08,190 And then what we'll do is, we will create some items 168 00:07:08,190 --> 00:07:10,020 and add them to the shopping list, right? 169 00:07:10,020 --> 00:07:11,940 So that's what test one is doing 170 00:07:11,940 --> 00:07:14,160 and you could see what I'm doing right here 171 00:07:14,160 --> 00:07:15,870 and let me grab my pen. 172 00:07:15,870 --> 00:07:17,910 Right here, we're simply displaying test one 173 00:07:17,910 --> 00:07:19,290 and that's done right up here, 174 00:07:19,290 --> 00:07:20,520 there's the output. 175 00:07:20,520 --> 00:07:23,880 I'm creating my shopping list and I'm adding, not apple, 176 00:07:23,880 --> 00:07:26,340 I'm adding grocery item apple. 177 00:07:26,340 --> 00:07:27,660 We've got to scope it. 178 00:07:27,660 --> 00:07:30,060 So I'm adding apple, milk and orange, 179 00:07:30,060 --> 00:07:31,890 and I'm creating a helicopter integer 180 00:07:31,890 --> 00:07:35,370 with a thousand and I'm going to push that guy back in. 181 00:07:35,370 --> 00:07:37,950 Now I can do that here because I'm casting. 182 00:07:37,950 --> 00:07:40,290 So remember, be very careful with casting, 183 00:07:40,290 --> 00:07:42,240 make sure your cast makes sense. 184 00:07:42,240 --> 00:07:43,740 In this case, it doesn't make sense really 185 00:07:43,740 --> 00:07:46,800 'cause I don't have an item with a 1000 code. 186 00:07:46,800 --> 00:07:49,260 Notice that if I try to add helicopter here, 187 00:07:49,260 --> 00:07:51,930 I'll get a compiler error because this is an int 188 00:07:51,930 --> 00:07:54,090 and it's doing a little bit of checking for me. 189 00:07:54,090 --> 00:07:57,390 The shopping list is expecting a grocery item, 190 00:07:57,390 --> 00:07:58,770 not an int. 191 00:07:58,770 --> 00:08:02,100 Here, I'm telling it, "Hey, I know what I'm doing. 192 00:08:02,100 --> 00:08:04,710 So do what I tell you to do." 193 00:08:04,710 --> 00:08:07,140 And that's not always a good thing. 194 00:08:07,140 --> 00:08:10,140 I'm doing the 350 item, which is the milk. 195 00:08:10,140 --> 00:08:12,030 So it's going to add that again. 196 00:08:12,030 --> 00:08:13,920 And when I'm done, I display the list. 197 00:08:13,920 --> 00:08:15,810 And here's the list that displays, I get apple, 198 00:08:15,810 --> 00:08:18,540 I get milk, I get orange, I get that invalid item 199 00:08:18,540 --> 00:08:22,890 which is this one right here on line 93. 200 00:08:22,890 --> 00:08:27,120 I get milk again because I'm adding the item code 350. 201 00:08:27,120 --> 00:08:31,320 And we've got five total items, four valid, one invalid. 202 00:08:31,320 --> 00:08:32,153 So there you go. 203 00:08:32,153 --> 00:08:34,169 That's very, very similar to the example 204 00:08:34,169 --> 00:08:36,419 that I did in the unscoped video. 205 00:08:36,419 --> 00:08:40,110 So now let's check this example, test two. 206 00:08:40,110 --> 00:08:40,950 For test two, 207 00:08:40,950 --> 00:08:43,020 I created a class just to show you 208 00:08:43,020 --> 00:08:45,300 how we can use these scoped enumerators 209 00:08:45,300 --> 00:08:48,180 or really unscoped enumerators inside a class. 210 00:08:48,180 --> 00:08:49,770 So here's an example. 211 00:08:49,770 --> 00:08:52,080 I've got a class called Player 212 00:08:52,080 --> 00:08:54,480 and this would model a player in a video game 213 00:08:54,480 --> 00:08:57,540 or something like that, where they've got a mode 214 00:08:57,540 --> 00:09:00,090 which is an attack, a defense or an idol, right? 215 00:09:00,090 --> 00:09:02,130 Their current mode in the game, 216 00:09:02,130 --> 00:09:05,610 a direction that they're facing, North, South, East or West. 217 00:09:05,610 --> 00:09:06,750 And they've got a name. 218 00:09:06,750 --> 00:09:09,720 So you can see those attributes of the class right here down 219 00:09:09,720 --> 00:09:12,990 at the bottom, right here with lines 129 to 131. 220 00:09:12,990 --> 00:09:15,000 So again, you can see that the player has a name, 221 00:09:15,000 --> 00:09:17,190 it has a mode of attack or defense, 222 00:09:17,190 --> 00:09:19,170 whatever their current mode is, 223 00:09:19,170 --> 00:09:21,720 and the direction that they're facing in the game. 224 00:09:21,720 --> 00:09:23,400 So those are the attributes. 225 00:09:23,400 --> 00:09:26,550 And if I scroll back up, we've got a constructor here, 226 00:09:26,550 --> 00:09:28,860 just like we've done before, nothing new. 227 00:09:28,860 --> 00:09:31,770 We've got our getters in our setters for the name, 228 00:09:31,770 --> 00:09:33,390 the mode and the direction. 229 00:09:33,390 --> 00:09:36,420 So let's write a couple of utility functions. 230 00:09:36,420 --> 00:09:38,910 The first one gets me the player mode. 231 00:09:38,910 --> 00:09:41,490 So if I pass in, not a player, 232 00:09:41,490 --> 00:09:46,490 but if I pass in a player mode, it's going to return attack, 233 00:09:46,650 --> 00:09:49,500 defense or idle as a string. 234 00:09:49,500 --> 00:09:51,090 That'll be a really handy function 235 00:09:51,090 --> 00:09:53,790 that I can call whenever I need to display that, 236 00:09:53,790 --> 00:09:55,080 for example. 237 00:09:55,080 --> 00:09:57,870 I also have a function that's going to 238 00:09:57,870 --> 00:09:58,920 give me the player direction 239 00:09:58,920 --> 00:10:00,690 and it works exactly the same way. 240 00:10:00,690 --> 00:10:02,970 It expects a player's direction, not a player, 241 00:10:02,970 --> 00:10:04,560 just the player's direction. 242 00:10:04,560 --> 00:10:07,110 And it returns the std::string here 243 00:10:07,110 --> 00:10:09,300 and it's going to return North, South, East 244 00:10:09,300 --> 00:10:11,880 or West depending on that enumeration. 245 00:10:11,880 --> 00:10:14,790 Since it's a scoped enumeration, I need to qualify it. 246 00:10:14,790 --> 00:10:15,660 And then finally, 247 00:10:15,660 --> 00:10:18,390 I've overloaded the stream insertion operator, 248 00:10:18,390 --> 00:10:19,590 and this is where those functions 249 00:10:19,590 --> 00:10:21,150 that I just wrote will be called. 250 00:10:21,150 --> 00:10:22,860 So stream insertion operator, 251 00:10:22,860 --> 00:10:25,920 if we're passing in a player object by reference 252 00:10:25,920 --> 00:10:29,370 in this case, by construct reference as we're supposed to, 253 00:10:29,370 --> 00:10:32,460 this is simply going to display player name 254 00:10:32,460 --> 00:10:34,740 and then it's going to get the player's name, 255 00:10:34,740 --> 00:10:35,970 then player mode, 256 00:10:35,970 --> 00:10:38,190 and it's going to get the player mode that function we wrote 257 00:10:38,190 --> 00:10:40,380 and it's going to pass in the player's mode 258 00:10:40,380 --> 00:10:42,000 rather than the entire player. 259 00:10:42,000 --> 00:10:42,900 We don't need to pass 260 00:10:42,900 --> 00:10:45,840 in the entire player to display the mode. 261 00:10:45,840 --> 00:10:48,060 And we're going to display player direction followed 262 00:10:48,060 --> 00:10:51,810 by get player direction and p.direction. 263 00:10:51,810 --> 00:10:53,250 We'll put an end line at the end 264 00:10:53,250 --> 00:10:56,040 and we'll return os, and now we'll be able to use that. 265 00:10:56,040 --> 00:10:58,110 So in test two, you can see the test. 266 00:10:58,110 --> 00:10:59,850 It's really, really simple here. 267 00:10:59,850 --> 00:11:02,490 I'm creating three player objects right here 268 00:11:02,490 --> 00:11:05,790 on lines 190 to 192. 269 00:11:05,790 --> 00:11:09,300 The first one is p1, it's cloud strife. 270 00:11:09,300 --> 00:11:12,900 It's current player mode is attack 271 00:11:12,900 --> 00:11:16,020 and its current direction is facing North. 272 00:11:16,020 --> 00:11:16,853 And you can see 273 00:11:16,853 --> 00:11:20,130 how we're using those enumerators right here. 274 00:11:20,130 --> 00:11:23,520 Also, you can see the way the scope works, right? 275 00:11:23,520 --> 00:11:26,370 it's not just mode attack, it's player mode attack 276 00:11:26,370 --> 00:11:29,850 because that enumeration is defined in the player class. 277 00:11:29,850 --> 00:11:31,200 So it's defined publicly 278 00:11:31,200 --> 00:11:33,330 within the scope of the player class. 279 00:11:33,330 --> 00:11:36,840 So we need to provide all the information 280 00:11:36,840 --> 00:11:39,000 that the compiler needs to do this. 281 00:11:39,000 --> 00:11:41,430 But look at the readability, again, 282 00:11:41,430 --> 00:11:42,780 that's very readable, right? 283 00:11:42,780 --> 00:11:45,270 Player one, player two is Tifa Lockhart 284 00:11:45,270 --> 00:11:47,580 in defense mode, facing West. 285 00:11:47,580 --> 00:11:48,900 This is so much easier 286 00:11:48,900 --> 00:11:51,540 than having magic numbers again in there. 287 00:11:51,540 --> 00:11:53,160 And the compiler's helping us out, 288 00:11:53,160 --> 00:11:54,780 it's checking for errors. 289 00:11:54,780 --> 00:11:57,060 So once I define those three player objects, 290 00:11:57,060 --> 00:11:59,640 I can display them really simply 291 00:11:59,640 --> 00:12:01,650 by just putting those player objects right 292 00:12:01,650 --> 00:12:04,560 on the output stream here with the insertion operator. 293 00:12:04,560 --> 00:12:05,850 And this is what we're going to get 294 00:12:05,850 --> 00:12:07,470 as the output right there. 295 00:12:07,470 --> 00:12:10,620 Player name, Cloud Strife, attack mode North, 296 00:12:10,620 --> 00:12:12,420 just like we did here. 297 00:12:12,420 --> 00:12:17,420 Tifa Lockhart, defense West, and Sephiroth, Idle, South. 298 00:12:18,540 --> 00:12:20,940 And you can see that display right there. 299 00:12:20,940 --> 00:12:22,320 Now, I didn't implement test three 300 00:12:22,320 --> 00:12:24,180 which is the rocket launch example. 301 00:12:24,180 --> 00:12:26,130 I'll leave that to you as an exercise. 302 00:12:26,130 --> 00:12:27,510 That way you can translate it 303 00:12:27,510 --> 00:12:29,910 from an unscoped to a scoped enumeration 304 00:12:29,910 --> 00:12:31,770 and play around with that and have some fun. 305 00:12:31,770 --> 00:12:33,930 So that covers enumerations. 306 00:12:33,930 --> 00:12:37,740 As you can see, at their core, they're very, very simple. 307 00:12:37,740 --> 00:12:41,190 Using them involves a lot because we can use a lot 308 00:12:41,190 --> 00:12:43,036 of advanced features in C++. 309 00:12:43,036 --> 00:12:46,320 We can use them with all kinds of control structures. 310 00:12:46,320 --> 00:12:47,850 We can use them inside classes. 311 00:12:47,850 --> 00:12:49,530 We can overload operators. 312 00:12:49,530 --> 00:12:51,660 We can get underlying types. 313 00:12:51,660 --> 00:12:54,030 We can do all kinds of really cool stuff. 314 00:12:54,030 --> 00:12:56,850 The big benefits, readability. 315 00:12:56,850 --> 00:13:00,213 Also, let the compiler help you find mistakes.