1 00:00:00,112 --> 00:00:02,520 (light music) 2 00:00:02,520 --> 00:00:05,340 (keyboard clickking) 3 00:00:05,340 --> 00:00:07,260 Frank: In this video, we'll look at what it means 4 00:00:07,260 --> 00:00:10,050 for an enumeration to be unscoped. 5 00:00:10,050 --> 00:00:11,370 In the last video, 6 00:00:11,370 --> 00:00:14,610 we looked at the structure and syntax of an enumeration 7 00:00:14,610 --> 00:00:18,030 and said that an enumeration's key defines its scope. 8 00:00:18,030 --> 00:00:21,330 So far we've only seen the singular enum key used 9 00:00:21,330 --> 00:00:23,340 and so you won't be surprised to hear that this key 10 00:00:23,340 --> 00:00:25,683 implements an unscoped enumeration. 11 00:00:26,970 --> 00:00:29,940 But what does it mean for an enumeration to be unscoped? 12 00:00:29,940 --> 00:00:31,890 When an enumeration is unscoped, 13 00:00:31,890 --> 00:00:33,870 its enumerators are unqualified 14 00:00:33,870 --> 00:00:35,820 and they're visible throughout the entire scope 15 00:00:35,820 --> 00:00:38,100 in which the enumeration was declared. 16 00:00:38,100 --> 00:00:39,480 This means that if we want 17 00:00:39,480 --> 00:00:41,640 to use an enumeration's enumerators, 18 00:00:41,640 --> 00:00:43,470 it's not necessary to specify 19 00:00:43,470 --> 00:00:46,680 which enumeration the enumerators belong to. 20 00:00:46,680 --> 00:00:48,960 Seems great, right, less work for us. 21 00:00:48,960 --> 00:00:50,220 But as we'll see later, 22 00:00:50,220 --> 00:00:52,200 this can sometimes cause issues 23 00:00:52,200 --> 00:00:54,930 and this is why scoped enumerations are so useful. 24 00:00:54,930 --> 00:00:56,040 In the meantime, let's look 25 00:00:56,040 --> 00:00:58,893 at some common uses of unscoped enumerations. 26 00:01:01,200 --> 00:01:03,750 One of the most common uses of enumerations 27 00:01:03,750 --> 00:01:06,090 is as conditionals and control structures 28 00:01:06,090 --> 00:01:08,370 such as if and switch statements. 29 00:01:08,370 --> 00:01:10,740 As we saw with the rocket launch example, 30 00:01:10,740 --> 00:01:13,710 by using an enumeration to represent the different states 31 00:01:13,710 --> 00:01:15,540 and sequences of the launch, 32 00:01:15,540 --> 00:01:17,640 we can create a readable control structure 33 00:01:17,640 --> 00:01:19,440 using if else statements. 34 00:01:19,440 --> 00:01:22,980 Now suppose the ordering of control is reversed as seen here 35 00:01:22,980 --> 00:01:25,110 so that the first condition evaluated 36 00:01:25,110 --> 00:01:26,940 is whether the state is Nominal 37 00:01:26,940 --> 00:01:28,500 and the last condition evaluated 38 00:01:28,500 --> 00:01:31,080 is whether the state is Engine_Failure. 39 00:01:31,080 --> 00:01:32,310 Can you think of any reason 40 00:01:32,310 --> 00:01:34,170 why this series of if else statements 41 00:01:34,170 --> 00:01:36,360 might not be the best implementation 42 00:01:36,360 --> 00:01:37,743 for our control structure? 43 00:01:39,030 --> 00:01:41,310 To understand why we might want to implement 44 00:01:41,310 --> 00:01:42,960 a different control structure, 45 00:01:42,960 --> 00:01:44,730 let's imagine that the state returned 46 00:01:44,730 --> 00:01:47,700 from the function get_state is Engine_Failure. 47 00:01:47,700 --> 00:01:50,520 Obviously we want to initiate the abort sequence 48 00:01:50,520 --> 00:01:52,110 as quickly as possible. 49 00:01:52,110 --> 00:01:54,030 But with the current implementation, 50 00:01:54,030 --> 00:01:57,240 we must first evaluate whether the state is Nominal 51 00:01:57,240 --> 00:02:00,540 and then evaluate whether the state is Inclement_Weather. 52 00:02:00,540 --> 00:02:03,930 Then only after each of those two states have been evaluated 53 00:02:03,930 --> 00:02:06,630 can we determine that the state is Engine_Failure 54 00:02:06,630 --> 00:02:09,660 and finally, initiate the abort sequence. 55 00:02:09,660 --> 00:02:11,400 I know what you're probably thinking. 56 00:02:11,400 --> 00:02:13,920 The extra time taken has to be negligible 57 00:02:13,920 --> 00:02:15,420 and for small control structures 58 00:02:15,420 --> 00:02:17,610 like this, it's certainly true. 59 00:02:17,610 --> 00:02:21,210 But what if instead we were evaluating 100 different states 60 00:02:21,210 --> 00:02:24,480 and again, the Engine_Failure state is evaluated last? 61 00:02:24,480 --> 00:02:26,550 That extra time taken in this case 62 00:02:26,550 --> 00:02:28,143 might not be so negligible. 63 00:02:29,130 --> 00:02:31,950 You may think to simply reorder the condition evaluations 64 00:02:31,950 --> 00:02:33,360 of the control structure, 65 00:02:33,360 --> 00:02:35,280 but we often want equal access time 66 00:02:35,280 --> 00:02:37,470 for each of our control evaluations 67 00:02:37,470 --> 00:02:40,380 meaning we want the Nominal state to be evaluated 68 00:02:40,380 --> 00:02:42,150 as quickly as possible, 69 00:02:42,150 --> 00:02:45,360 as well as the Engine_Failure state and so forth. 70 00:02:45,360 --> 00:02:49,020 So is there a way we can do this using if else statements? 71 00:02:49,020 --> 00:02:52,083 Unfortunately not, but we can do it using switch statements. 72 00:02:53,940 --> 00:02:55,260 Switch statements are by far 73 00:02:55,260 --> 00:02:58,590 the most popular control structure used with enumerations. 74 00:02:58,590 --> 00:03:01,110 This is not because they provide better readability 75 00:03:01,110 --> 00:03:02,700 than if else statements, 76 00:03:02,700 --> 00:03:06,030 but also because for five or more cases generally, 77 00:03:06,030 --> 00:03:08,040 they're implemented as jump tables 78 00:03:08,040 --> 00:03:11,580 which provide equal access time for all cases. 79 00:03:11,580 --> 00:03:14,490 This means that regardless of where we position the Nominal 80 00:03:14,490 --> 00:03:17,280 and Engine_Failure states in the control structure, 81 00:03:17,280 --> 00:03:19,293 they'll be evaluated in equal time. 82 00:03:20,460 --> 00:03:21,780 It should be noted though 83 00:03:21,780 --> 00:03:24,180 that we can only use switch statements with enumerations 84 00:03:24,180 --> 00:03:25,980 so long as the enumerators we use 85 00:03:25,980 --> 00:03:29,190 as switch cases have unique values. 86 00:03:29,190 --> 00:03:30,870 Otherwise the switch will not be able 87 00:03:30,870 --> 00:03:32,700 to discern between its cases 88 00:03:32,700 --> 00:03:34,143 and the code won't compile. 89 00:03:36,720 --> 00:03:39,090 As we saw with our accidental launch scenario, 90 00:03:39,090 --> 00:03:40,230 we might want the user 91 00:03:40,230 --> 00:03:42,333 to initialize enumeration type variable. 92 00:03:43,260 --> 00:03:45,960 Unfortunately we can't use the standard cin command 93 00:03:45,960 --> 00:03:47,550 with the extraction operator 94 00:03:47,550 --> 00:03:49,740 because the extraction operator has no knowledge 95 00:03:49,740 --> 00:03:51,840 of what a State type variable is 96 00:03:51,840 --> 00:03:53,013 or how to deal with it. 97 00:03:54,060 --> 00:03:56,760 Thankfully we have two methods to deal with this. 98 00:03:56,760 --> 00:04:00,330 The first is to extract the user input value into a type 99 00:04:00,330 --> 00:04:02,880 that the extraction operator does know about 100 00:04:02,880 --> 00:04:05,820 and then cast it to the State type variable. 101 00:04:05,820 --> 00:04:08,490 The second is to overload the extraction operator 102 00:04:08,490 --> 00:04:10,380 to deal with State type variables. 103 00:04:10,380 --> 00:04:12,130 Let's take a look at both of these. 104 00:04:15,570 --> 00:04:17,220 Here we can see the first method 105 00:04:17,220 --> 00:04:20,250 which reads the user input into a temporary variable 106 00:04:20,250 --> 00:04:23,340 which is then cast to a State type variable. 107 00:04:23,340 --> 00:04:25,890 When we declare the type of the temporary variable, 108 00:04:25,890 --> 00:04:28,890 in some cases the underlying type of an enumeration 109 00:04:28,890 --> 00:04:30,480 might not be obvious, 110 00:04:30,480 --> 00:04:32,171 so we can use the class template, 111 00:04:32,171 --> 00:04:34,890 underlying_type_t, to deduce it. 112 00:04:34,890 --> 00:04:36,450 In this case, the underlying type 113 00:04:36,450 --> 00:04:38,610 of the state enumeration is integer, 114 00:04:38,610 --> 00:04:42,870 so the type of the user input variable will also be integer. 115 00:04:42,870 --> 00:04:44,040 It's important to note 116 00:04:44,040 --> 00:04:46,950 that when we cast variables to enumeration types, 117 00:04:46,950 --> 00:04:49,530 the value of the variable does not change. 118 00:04:49,530 --> 00:04:51,180 This means that there's no guarantee 119 00:04:51,180 --> 00:04:53,610 that the cast state enumeration type variable 120 00:04:53,610 --> 00:04:55,470 will have a value corresponding 121 00:04:55,470 --> 00:04:57,483 to the enumeration's enumerators. 122 00:04:59,250 --> 00:05:02,130 For example, if the user were to enter the value three, 123 00:05:02,130 --> 00:05:03,030 it would be cast 124 00:05:03,030 --> 00:05:06,360 to the State type variable state with no issues. 125 00:05:06,360 --> 00:05:07,920 Obviously this is not what we want 126 00:05:07,920 --> 00:05:11,700 since three does not correspond to any state enumerator. 127 00:05:11,700 --> 00:05:13,770 Our only recourse in this situation 128 00:05:13,770 --> 00:05:15,330 is to implement our own checks 129 00:05:15,330 --> 00:05:17,520 to ensure that the variable we're casting 130 00:05:17,520 --> 00:05:19,500 has a value corresponding 131 00:05:19,500 --> 00:05:21,663 to one of the enumerations enumerators. 132 00:05:23,100 --> 00:05:25,410 This is usually done by using a switch statement 133 00:05:25,410 --> 00:05:28,140 with the condition being the variable to be casted 134 00:05:28,140 --> 00:05:31,113 and the cases being each of the enumeration's enumerators. 135 00:05:32,310 --> 00:05:34,830 There are many ways to perform these kinds of checks, 136 00:05:34,830 --> 00:05:36,180 but the important thing to remember 137 00:05:36,180 --> 00:05:38,100 is that you're responsible for ensuring 138 00:05:38,100 --> 00:05:40,680 that a variable cast to an enumeration type 139 00:05:40,680 --> 00:05:43,410 will have a valid enumerator value. 140 00:05:43,410 --> 00:05:44,550 In an example like this, 141 00:05:44,550 --> 00:05:47,490 you may want to set the output stream to a fail state 142 00:05:47,490 --> 00:05:49,143 in the case of an invalid state. 143 00:05:51,150 --> 00:05:52,440 The second method of reading 144 00:05:52,440 --> 00:05:54,900 user input values into enumeration types 145 00:05:54,900 --> 00:05:57,810 is by overloading the extraction operator. 146 00:05:57,810 --> 00:06:00,360 Using this method, we overload the extraction operator 147 00:06:00,360 --> 00:06:04,200 to take as parameters a reference to the input stream 148 00:06:04,200 --> 00:06:05,643 and a reference to the state variable 149 00:06:05,643 --> 00:06:07,803 that the user input will be read into. 150 00:06:08,730 --> 00:06:10,170 It's important that we declare 151 00:06:10,170 --> 00:06:12,000 an enumeration in the same scope 152 00:06:12,000 --> 00:06:13,620 as any function referencing 153 00:06:13,620 --> 00:06:15,573 the enumeration or its enumerators. 154 00:06:16,440 --> 00:06:18,747 This is to ensure that the enumeration type 155 00:06:18,747 --> 00:06:20,580 and its enumerators can be accessed 156 00:06:20,580 --> 00:06:22,560 from within the function. 157 00:06:22,560 --> 00:06:25,560 In this case, we've declared the state enumeration 158 00:06:25,560 --> 00:06:27,390 in the same global namespace 159 00:06:27,390 --> 00:06:30,570 that contains the overloaded extraction operator function. 160 00:06:30,570 --> 00:06:33,000 Within the function, again, we have declared 161 00:06:33,000 --> 00:06:35,730 a temporary user input variable with the same type 162 00:06:35,730 --> 00:06:38,520 as the underlying type of the enumeration. 163 00:06:38,520 --> 00:06:42,330 Next, the user's input is extracted from the input stream 164 00:06:42,330 --> 00:06:44,430 and assigned to the temporary variable 165 00:06:44,430 --> 00:06:46,950 which is then checked to ensure that its value 166 00:06:46,950 --> 00:06:49,830 corresponds to a valid state enumerator. 167 00:06:49,830 --> 00:06:52,530 If it does, the temporary variable is cast 168 00:06:52,530 --> 00:06:54,210 to the reference state variable. 169 00:06:54,210 --> 00:06:56,730 If it doesn't, the user is displayed a message 170 00:06:56,730 --> 00:07:00,030 informing them that they have not entered a valid state. 171 00:07:00,030 --> 00:07:01,860 Finally, the input stream is returned 172 00:07:01,860 --> 00:07:03,450 to the calling function. 173 00:07:03,450 --> 00:07:04,740 As you may have noticed, 174 00:07:04,740 --> 00:07:07,260 this method is identical to the first 175 00:07:07,260 --> 00:07:08,760 but this time we've implemented it 176 00:07:08,760 --> 00:07:11,100 as an overloaded extraction operator. 177 00:07:11,100 --> 00:07:14,133 This is so we can write clean readable code like this. 178 00:07:15,210 --> 00:07:17,670 Now that we've seen how to use cin in with enumerations, 179 00:07:17,670 --> 00:07:18,960 let's switch our focus to see 180 00:07:18,960 --> 00:07:22,267 how we can use cout with enumerations. 181 00:07:23,340 --> 00:07:25,620 To display enumeration type variables, 182 00:07:25,620 --> 00:07:27,780 we can use the standard cout 183 00:07:27,780 --> 00:07:29,400 and the insertion operator. 184 00:07:29,400 --> 00:07:30,233 When we do so, 185 00:07:30,233 --> 00:07:33,270 the enumeration type variable is implicitly converted 186 00:07:33,270 --> 00:07:34,950 to its underlying type 187 00:07:34,950 --> 00:07:37,110 and its value is displayed. 188 00:07:37,110 --> 00:07:40,230 This means that when we display enumeration type variables, 189 00:07:40,230 --> 00:07:42,420 it's always their value that's displayed 190 00:07:42,420 --> 00:07:44,730 and never their enumerator name. 191 00:07:44,730 --> 00:07:47,880 This makes sense since an enumerator's name isn't a string, 192 00:07:47,880 --> 00:07:49,140 but simply a name used 193 00:07:49,140 --> 00:07:51,393 to identify its value within the code. 194 00:07:53,310 --> 00:07:55,290 Sometimes it may be useful to display 195 00:07:55,290 --> 00:07:57,780 the name of the enumeration type variable 196 00:07:57,780 --> 00:07:59,250 and so to accomplish this, 197 00:07:59,250 --> 00:08:01,170 we can implement a simple switch statement 198 00:08:01,170 --> 00:08:03,330 using the variable as the condition 199 00:08:03,330 --> 00:08:06,510 and its cases being the enumerations enumerators. 200 00:08:06,510 --> 00:08:07,710 As you may have guessed, 201 00:08:07,710 --> 00:08:09,450 we could even implement this functionality 202 00:08:09,450 --> 00:08:11,613 by overloading the insertion operator. 203 00:08:15,540 --> 00:08:17,730 In this case, we overload the insertion operator 204 00:08:17,730 --> 00:08:19,320 to take as parameters, 205 00:08:19,320 --> 00:08:21,360 a reference to the output stream, 206 00:08:21,360 --> 00:08:22,950 and a reference to the state variable 207 00:08:22,950 --> 00:08:25,020 whose name will be displayed. 208 00:08:25,020 --> 00:08:27,270 Again, it's important to declare the enumeration 209 00:08:27,270 --> 00:08:29,880 in the same namespace as the overloaded function 210 00:08:29,880 --> 00:08:31,350 so that the enumeration type 211 00:08:31,350 --> 00:08:33,000 and its enumerators can be accessed 212 00:08:33,000 --> 00:08:34,250 from within the function. 213 00:08:35,280 --> 00:08:36,929 Within the overloaded function, 214 00:08:36,929 --> 00:08:38,429 the reference state is compared 215 00:08:38,429 --> 00:08:39,840 to the enumeration's enumerators 216 00:08:39,840 --> 00:08:41,309 and the appropriate enumerator name 217 00:08:41,309 --> 00:08:43,710 is inserted into the output stream. 218 00:08:43,710 --> 00:08:45,510 Finally, the output stream is returned 219 00:08:45,510 --> 00:08:47,400 to the calling function. 220 00:08:47,400 --> 00:08:49,350 By overloading the insertion operator 221 00:08:49,350 --> 00:08:51,960 to display the names of State type variables, 222 00:08:51,960 --> 00:08:54,513 we can write clean, readable code like this. 223 00:08:55,860 --> 00:08:58,140 Now now that we've covered some of the most common uses 224 00:08:58,140 --> 00:09:00,540 and pitfalls of unscoped enumerations, 225 00:09:00,540 --> 00:09:01,980 let's head over to the IDE 226 00:09:01,980 --> 00:09:03,363 and see some more examples. 227 00:09:05,580 --> 00:09:07,680 Okay, so I'm in the IDE. 228 00:09:07,680 --> 00:09:09,900 I am in the Enumerations workspace 229 00:09:09,900 --> 00:09:13,440 and I'm in the UnscopedEnums project. 230 00:09:13,440 --> 00:09:14,970 What I've done in this project is written 231 00:09:14,970 --> 00:09:17,220 three tests that exercise different kinds 232 00:09:17,220 --> 00:09:20,640 of functionalities for unscoped enumerations. 233 00:09:20,640 --> 00:09:23,070 Right now I've got test two and test three commented out, 234 00:09:23,070 --> 00:09:24,780 so we're just running test one. 235 00:09:24,780 --> 00:09:25,613 Now I've already built it 236 00:09:25,613 --> 00:09:27,780 and the output is over here on the right, 237 00:09:27,780 --> 00:09:29,430 but let's look at the code that I wrote 238 00:09:29,430 --> 00:09:31,440 so you get an idea of what's going on here. 239 00:09:31,440 --> 00:09:34,560 So the first thing I did was I created an enumeration 240 00:09:34,560 --> 00:09:35,610 and it's called Direction, 241 00:09:35,610 --> 00:09:37,680 and you can see it right there. 242 00:09:37,680 --> 00:09:39,000 Notice that it's unscoped 243 00:09:39,000 --> 00:09:41,790 and the enumerators are North, South, East, and West 244 00:09:41,790 --> 00:09:44,220 and as we know, this gets a zero, this gets a one, 245 00:09:44,220 --> 00:09:46,650 this gets a two, and West gets the three, 246 00:09:46,650 --> 00:09:49,740 and that's automatically done by the compiler. 247 00:09:49,740 --> 00:09:50,910 Now the first thing we wanna know 248 00:09:50,910 --> 00:09:53,640 is if we try to create another enumeration, 249 00:09:53,640 --> 00:09:54,840 let's say you call it Street 250 00:09:54,840 --> 00:09:58,140 that models different kinds of street names, for example, 251 00:09:58,140 --> 00:10:01,320 and we've got Main, North Street, Elm Street, and so forth. 252 00:10:01,320 --> 00:10:04,830 We can't do this because we've got North twice 253 00:10:04,830 --> 00:10:06,420 and the compiler's gonna say 254 00:10:06,420 --> 00:10:07,680 I don't know what you're trying to do. 255 00:10:07,680 --> 00:10:09,270 You're trying to redeclare that. 256 00:10:09,270 --> 00:10:10,830 So this is one of the limitations 257 00:10:10,830 --> 00:10:14,370 as I mentioned in the slides with unscoped enumerations 258 00:10:14,370 --> 00:10:16,250 and we can handle that with scoped enumerations 259 00:10:16,250 --> 00:10:17,520 in the next example. 260 00:10:17,520 --> 00:10:18,540 That's where we're at here 261 00:10:18,540 --> 00:10:21,840 and let me just show you what's going on in this example. 262 00:10:21,840 --> 00:10:23,280 Here I wrote a function. 263 00:10:23,280 --> 00:10:25,560 The function is called direction_to_string. 264 00:10:25,560 --> 00:10:27,450 You can see the name of the function right there. 265 00:10:27,450 --> 00:10:30,420 It expects a direction parameter 266 00:10:30,420 --> 00:10:34,290 and depending on the enumerator of that direction, 267 00:10:34,290 --> 00:10:36,330 we're going to return a string. 268 00:10:36,330 --> 00:10:38,220 It's either going to be North, South, East, or West 269 00:10:38,220 --> 00:10:40,140 depending on what the case 270 00:10:40,140 --> 00:10:42,930 of that enumerator is right there, okay? 271 00:10:42,930 --> 00:10:44,760 And as you can see, it's returning a string. 272 00:10:44,760 --> 00:10:47,220 So this is just a real handy utility function 273 00:10:47,220 --> 00:10:48,630 where you pass in a direction 274 00:10:48,630 --> 00:10:50,820 and it's going to return North, South, East, West, 275 00:10:50,820 --> 00:10:53,790 or unknown direction as a string. 276 00:10:53,790 --> 00:10:54,623 So we've got that 277 00:10:54,623 --> 00:10:55,470 and here's the test. 278 00:10:55,470 --> 00:10:56,820 The test is really straightforward 279 00:10:56,820 --> 00:10:58,950 and you can see the output over here on the right. 280 00:10:58,950 --> 00:10:59,940 So let's walk through this. 281 00:10:59,940 --> 00:11:02,010 You can see exactly what I'm talking about. 282 00:11:02,010 --> 00:11:04,770 So the first thing we're doing is we're outputting tests 283 00:11:04,770 --> 00:11:06,840 and that's the output you see right there, 284 00:11:06,840 --> 00:11:10,320 and we're creating a variable here called direction 285 00:11:10,320 --> 00:11:13,800 and that variable is of a Direction type. 286 00:11:13,800 --> 00:11:15,630 Now remember when we create an enumeration, 287 00:11:15,630 --> 00:11:17,490 we're creating a new type in the system. 288 00:11:17,490 --> 00:11:21,120 So this is very similar to doing something like int i 289 00:11:21,120 --> 00:11:23,700 and initializing it to zero let's say in this case. 290 00:11:23,700 --> 00:11:24,780 So we're using a type, 291 00:11:24,780 --> 00:11:26,490 we're creating a variable, 292 00:11:26,490 --> 00:11:27,600 and we're initializing it. 293 00:11:27,600 --> 00:11:30,270 Same thing, we're using the type, 294 00:11:30,270 --> 00:11:31,770 a new type that we've just created 295 00:11:31,770 --> 00:11:33,600 when we created that enumeration. 296 00:11:33,600 --> 00:11:35,280 There is the variable name 297 00:11:35,280 --> 00:11:37,491 and there's the initializer, okay? 298 00:11:37,491 --> 00:11:39,870 So that's it, I've initialized it to North. 299 00:11:39,870 --> 00:11:41,910 Remember what we had originally here, 300 00:11:41,910 --> 00:11:45,600 we had North was zero, South was one, 301 00:11:45,600 --> 00:11:47,520 East was two, and West was three. 302 00:11:47,520 --> 00:11:51,060 So right now that enumerator value is zero, right? 303 00:11:51,060 --> 00:11:52,560 That's the underlying value. 304 00:11:52,560 --> 00:11:54,000 So we're gonna display Direction 305 00:11:54,000 --> 00:11:55,380 and then we're just gonna pass in 306 00:11:55,380 --> 00:11:58,320 direction to that overloaded operator right here. 307 00:11:58,320 --> 00:11:59,850 As far as that's concerned, 308 00:11:59,850 --> 00:12:01,020 this is an integer. 309 00:12:01,020 --> 00:12:03,480 Now scoped enumerators work very differently, 310 00:12:03,480 --> 00:12:05,280 but let's just talk about unscoped here. 311 00:12:05,280 --> 00:12:06,900 So this is going to display zero 312 00:12:06,900 --> 00:12:08,760 and that's what's happening here. 313 00:12:08,760 --> 00:12:10,470 Then I'm calling direction_to_string, 314 00:12:10,470 --> 00:12:11,550 I'm passing in direction. 315 00:12:11,550 --> 00:12:14,100 That's going to convert it to a std string 316 00:12:14,100 --> 00:12:16,080 as we saw in the function a minute ago 317 00:12:16,080 --> 00:12:18,240 and it's gonna display North. 318 00:12:18,240 --> 00:12:20,130 If we set the direction to West, 319 00:12:20,130 --> 00:12:21,900 it's going to do exactly the same thing. 320 00:12:21,900 --> 00:12:22,980 It's gonna display three 321 00:12:22,980 --> 00:12:24,930 and then West in this case. 322 00:12:24,930 --> 00:12:27,690 If we try to set the direction to five, for example, 323 00:12:27,690 --> 00:12:28,740 we're gonna get a compiler error 324 00:12:28,740 --> 00:12:31,290 because five is not valid. 325 00:12:31,290 --> 00:12:34,440 Be very careful when you're casting enumerators. 326 00:12:34,440 --> 00:12:36,237 You could cast things that aren't there 327 00:12:36,237 --> 00:12:37,290 and that's a problem. 328 00:12:37,290 --> 00:12:39,030 So here's an example here. 329 00:12:39,030 --> 00:12:42,090 I'm casting, remember direction is my variable. 330 00:12:42,090 --> 00:12:45,450 I'm casting 100 to a direction type. 331 00:12:45,450 --> 00:12:47,910 The compiler assumes you know what you're doing. 332 00:12:47,910 --> 00:12:48,980 Remember right now all we've got 333 00:12:48,980 --> 00:12:51,300 is zero, one, two, and three in there, right? 334 00:12:51,300 --> 00:12:53,280 North, South, East, and West. 335 00:12:53,280 --> 00:12:54,990 But if you're doing a cast like this, 336 00:12:54,990 --> 00:12:56,463 the compiler says okay. 337 00:12:57,618 --> 00:12:58,451 You know what you're doing, 338 00:12:58,451 --> 00:12:59,400 so I'm gonna let you do it. 339 00:12:59,400 --> 00:13:01,647 And notice what displays displays, 100, 340 00:13:01,647 --> 00:13:04,350 and then when we try to display the to_string, 341 00:13:04,350 --> 00:13:06,360 we get unknown direction. 342 00:13:06,360 --> 00:13:10,050 And this is very, very similar to doing a static cast, 343 00:13:10,050 --> 00:13:11,640 so this is what's happening here. 344 00:13:11,640 --> 00:13:12,510 I just wrote this here 345 00:13:12,510 --> 00:13:14,220 so that you can understand what's happening. 346 00:13:14,220 --> 00:13:15,600 We come up here 347 00:13:15,600 --> 00:13:17,580 and you guys could try this out on your own. 348 00:13:17,580 --> 00:13:19,500 If we come up here to the top 349 00:13:19,500 --> 00:13:24,500 and we do something like North is one, South is 10, 350 00:13:25,227 --> 00:13:27,420 and then East and West would get 11, 351 00:13:27,420 --> 00:13:29,550 then when you display these values here, 352 00:13:29,550 --> 00:13:31,710 you'll get different displays. 353 00:13:31,710 --> 00:13:33,450 Okay, so that takes care of test one. 354 00:13:33,450 --> 00:13:35,460 You can play around with it and modify things, 355 00:13:35,460 --> 00:13:37,293 so let's switch over to test two. 356 00:13:39,330 --> 00:13:40,470 Okay, so I've gone ahead 357 00:13:40,470 --> 00:13:41,850 and commented out test one 358 00:13:41,850 --> 00:13:44,370 and uncommented out test two here, 359 00:13:44,370 --> 00:13:46,260 and I've rerun the program 360 00:13:46,260 --> 00:13:48,060 and this is the output you can see over here. 361 00:13:48,060 --> 00:13:50,760 So now let's talk about what's going on in test two. 362 00:13:50,760 --> 00:13:52,890 Let me scroll back up to test two. 363 00:13:52,890 --> 00:13:54,150 So here's the enumeration 364 00:13:54,150 --> 00:13:57,660 that I'm using for the test two example. 365 00:13:57,660 --> 00:14:00,399 In this case, I'm modeling a Grocery_Item. 366 00:14:00,399 --> 00:14:02,310 That's the enumeration I've created 367 00:14:02,310 --> 00:14:04,890 and my enumerators are Milk, Bread, Apple, and Orange 368 00:14:04,890 --> 00:14:06,000 and again, behind the scenes 369 00:14:06,000 --> 00:14:08,490 we're getting a zero, a one, a two, and a three. 370 00:14:08,490 --> 00:14:11,370 And if we've got specific codes that we could use 371 00:14:11,370 --> 00:14:12,930 and I believe I'm doing that 372 00:14:12,930 --> 00:14:14,670 a little bit later in the scoped enumeration. 373 00:14:14,670 --> 00:14:17,130 So let's say that Milk is 350 374 00:14:17,130 --> 00:14:19,890 and Bread might be 150 or something like that. 375 00:14:19,890 --> 00:14:22,380 Those might be internal codes that we're using 376 00:14:22,380 --> 00:14:24,600 that represent the code for Milk, 377 00:14:24,600 --> 00:14:26,280 the code for Bread and so forth. 378 00:14:26,280 --> 00:14:27,750 So if we need something like that, 379 00:14:27,750 --> 00:14:29,610 that's perfectly valid to do. 380 00:14:29,610 --> 00:14:30,480 But in this case, 381 00:14:30,480 --> 00:14:32,370 I'm just gonna use the implicit initial 382 00:14:32,370 --> 00:14:34,380 is zero, one, two, and three. 383 00:14:34,380 --> 00:14:37,230 Now rather than having a function called to_string 384 00:14:37,230 --> 00:14:40,050 like the one we created a little bit ago in test one, 385 00:14:40,050 --> 00:14:42,990 I wanna overload the insertion operator 386 00:14:42,990 --> 00:14:46,650 'cause I want to be able to take these enumeration variables 387 00:14:46,650 --> 00:14:48,870 and just put them right on an output stream. 388 00:14:48,870 --> 00:14:51,540 And much easier than having to call a function 389 00:14:51,540 --> 00:14:54,660 and it blends right into the way C++ feels. 390 00:14:54,660 --> 00:14:57,090 So in this case, I've covered this in the class. 391 00:14:57,090 --> 00:14:59,250 If you're not familiar with overloading operators, 392 00:14:59,250 --> 00:15:01,230 there's a whole section in the course about it. 393 00:15:01,230 --> 00:15:04,740 So in this case, I'm overloading the insertion operator 394 00:15:04,740 --> 00:15:07,121 and I'm inserting a grocery_item 395 00:15:07,121 --> 00:15:09,931 or the string representation of a grocery_item 396 00:15:09,931 --> 00:15:12,240 into an output stream. 397 00:15:12,240 --> 00:15:13,560 So really simple, right? 398 00:15:13,560 --> 00:15:16,320 There's the grocery_item, I'm switching off of it. 399 00:15:16,320 --> 00:15:18,720 We could have used an if else ladder if we want, 400 00:15:18,720 --> 00:15:20,430 but in this case, I'm using a switch. 401 00:15:20,430 --> 00:15:21,330 I'm switching off of it. 402 00:15:21,330 --> 00:15:24,990 If it's Milk, I'm putting Milk on the output stream. 403 00:15:24,990 --> 00:15:27,720 Bread, Apple, Orange, if it's something else, 404 00:15:27,720 --> 00:15:29,550 I'm writing invalid object 405 00:15:29,550 --> 00:15:31,260 and I'm returning the output stream. 406 00:15:31,260 --> 00:15:33,360 And now we also have a little test function 407 00:15:33,360 --> 00:15:34,470 here that I've written 408 00:15:34,470 --> 00:15:36,000 which can come in really handy. 409 00:15:36,000 --> 00:15:37,767 It's called is_valid_grocery_item 410 00:15:37,767 --> 00:15:39,540 and it returns a Boolean, right? 411 00:15:39,540 --> 00:15:42,600 A true-false value, so given a grocery_item, 412 00:15:42,600 --> 00:15:44,550 is it a valid numerator? 413 00:15:44,550 --> 00:15:46,050 Well, it is a valid enumerator 414 00:15:46,050 --> 00:15:48,000 if it's one of the ones that I've defined, right? 415 00:15:48,000 --> 00:15:49,230 Milk, Bread, Apple, or Orange. 416 00:15:49,230 --> 00:15:52,920 So in the case of any of these, I'm returning true. 417 00:15:52,920 --> 00:15:54,840 Otherwise I'm returning false. 418 00:15:54,840 --> 00:15:55,673 If I return false 419 00:15:55,673 --> 00:15:57,210 and I've got something else in there, right? 420 00:15:57,210 --> 00:15:59,400 I've probably cast it to something. 421 00:15:59,400 --> 00:16:02,850 And now I want to display a grocery list 422 00:16:02,850 --> 00:16:04,320 and that's what test two is all about, 423 00:16:04,320 --> 00:16:05,520 and test two's down here. 424 00:16:05,520 --> 00:16:07,410 I'll show you what that looks like in a moment. 425 00:16:07,410 --> 00:16:08,880 But the idea with this function 426 00:16:08,880 --> 00:16:11,940 is the function's called display_grocery_list 427 00:16:11,940 --> 00:16:15,153 and it expects a std vector of Grocery_Items. 428 00:16:16,290 --> 00:16:19,230 So basically a collection of Grocery_Items 429 00:16:19,230 --> 00:16:21,180 and those guys are enumerations. 430 00:16:21,180 --> 00:16:23,340 So all I'm doing is I'm looping, 431 00:16:23,340 --> 00:16:26,250 you can see right here I'm using a range-based for loop. 432 00:16:26,250 --> 00:16:30,060 I'm looping over that grocery_list right here 433 00:16:30,060 --> 00:16:32,910 and for each grocery_item, I'm displaying it. 434 00:16:32,910 --> 00:16:33,870 How am I displaying it? 435 00:16:33,870 --> 00:16:35,730 I'm using that overloaded operator 436 00:16:35,730 --> 00:16:38,160 that I just overloaded a moment ago 437 00:16:38,160 --> 00:16:41,430 and I'm also keeping track of how many invalid items 438 00:16:41,430 --> 00:16:43,290 and how many valid items I've had 439 00:16:43,290 --> 00:16:47,400 using my is_valid_grocery_item function that I wrote. 440 00:16:47,400 --> 00:16:48,450 So that's all we're doing. 441 00:16:48,450 --> 00:16:50,580 We're looping through each element in that list, 442 00:16:50,580 --> 00:16:52,650 we're displaying it, and then we're checking 443 00:16:52,650 --> 00:16:54,180 was it a valid item, yes or no, 444 00:16:54,180 --> 00:16:55,980 and keep counters for those 445 00:16:55,980 --> 00:16:58,800 and then at the end, we're just displaying some information. 446 00:16:58,800 --> 00:17:01,320 And now let's look at the actual example 447 00:17:01,320 --> 00:17:02,640 which is right here 448 00:17:02,640 --> 00:17:04,170 and in this case, 449 00:17:04,170 --> 00:17:05,490 this one's actually pretty interesting 450 00:17:05,490 --> 00:17:07,589 'cause you can see I'm creating my shopping list here 451 00:17:07,589 --> 00:17:10,450 which is a std vector of Grocery_Items 452 00:17:11,579 --> 00:17:15,569 and I'm pushing back Apple, Apple, Milk, Orange. 453 00:17:15,569 --> 00:17:17,550 Those are all valid enumerators, right? 454 00:17:17,550 --> 00:17:20,339 The std vector can contain those 455 00:17:20,339 --> 00:17:22,800 because it contains Grocery_Items. 456 00:17:22,800 --> 00:17:25,020 What we're gonna do is we're gonna add them to that vector. 457 00:17:25,020 --> 00:17:25,853 That's what that's doing. 458 00:17:25,853 --> 00:17:27,990 That's what the pushback does. 459 00:17:27,990 --> 00:17:29,580 In this case, if I try to say something 460 00:17:29,580 --> 00:17:31,680 like Grocery_Item item is 100, 461 00:17:31,680 --> 00:17:33,300 I'm gonna get a compiler error. 462 00:17:33,300 --> 00:17:35,070 The compiler won't let me do that. 463 00:17:35,070 --> 00:17:37,740 However if I create an integer called Helicopter 464 00:17:37,740 --> 00:17:39,930 or some other silly name 465 00:17:39,930 --> 00:17:41,280 and initialize it to 100 466 00:17:41,280 --> 00:17:42,660 and I push that, 467 00:17:42,660 --> 00:17:43,680 it's gonna let me push it 468 00:17:43,680 --> 00:17:46,920 but it's gonna be an invalid item when I display it. 469 00:17:46,920 --> 00:17:49,350 In this case, if I create a Grocery_Item 470 00:17:49,350 --> 00:17:51,300 and initialize it to zero 471 00:17:51,300 --> 00:17:53,160 and this is a cast, 472 00:17:53,160 --> 00:17:54,390 that's gonna be Milk, right? 473 00:17:54,390 --> 00:17:58,260 Because Milk was the zero value enumerator 474 00:17:58,260 --> 00:18:00,690 in that enumeration, so that's what we're doing. 475 00:18:00,690 --> 00:18:02,220 We're just pushing some items on there 476 00:18:02,220 --> 00:18:03,540 and then I'm displaying that list 477 00:18:03,540 --> 00:18:05,070 with the function I just showed you. 478 00:18:05,070 --> 00:18:06,990 So when this runs, this is what we get. 479 00:18:06,990 --> 00:18:10,290 We get Apple, Apple, Milk, Orange 480 00:18:10,290 --> 00:18:11,310 and you can see them right here. 481 00:18:11,310 --> 00:18:13,560 Apple, Apple, Milk, Orange. 482 00:18:13,560 --> 00:18:15,150 Then we're gonna get an invalid item 483 00:18:15,150 --> 00:18:18,540 which is this guy right here, the Helicopter, 484 00:18:18,540 --> 00:18:19,920 and then this guy is zero 485 00:18:19,920 --> 00:18:21,420 so we're gonna get Milk again. 486 00:18:22,320 --> 00:18:25,740 And since we're keeping track of valid and invalid items, 487 00:18:25,740 --> 00:18:28,470 you could see here that we've got six total items, 488 00:18:28,470 --> 00:18:30,630 five are valid and one is invalid, 489 00:18:30,630 --> 00:18:34,203 and that would be this guy right here, the Helicopter. 490 00:18:35,760 --> 00:18:37,350 Okay, so that covers test two 491 00:18:37,350 --> 00:18:39,540 and again, play around with this, change some things, 492 00:18:39,540 --> 00:18:40,620 try some things out, 493 00:18:40,620 --> 00:18:42,180 and you'll really get a feel for it. 494 00:18:42,180 --> 00:18:43,890 The important thing to understand here 495 00:18:43,890 --> 00:18:46,340 is just how much more readable this code becomes. 496 00:18:47,730 --> 00:18:50,160 Okay, so finally we're in test three. 497 00:18:50,160 --> 00:18:52,200 Okay, so let me show you what's going on in test three. 498 00:18:52,200 --> 00:18:55,590 In test three, we've got an enumeration state, 499 00:18:55,590 --> 00:18:56,490 that is the state 500 00:18:56,490 --> 00:18:58,271 which is either Engine_Failure, 501 00:18:58,271 --> 00:19:00,720 Inclement_Weather, Nominal, or Unknown. 502 00:19:00,720 --> 00:19:01,920 Now this is a common thing 503 00:19:01,920 --> 00:19:03,690 that you'll see a lot of times in enumerations, 504 00:19:03,690 --> 00:19:07,470 some sort of unknown or unspecified state. 505 00:19:07,470 --> 00:19:09,180 A lot of times it comes in real handy 506 00:19:09,180 --> 00:19:11,490 because sometimes we get strange values 507 00:19:11,490 --> 00:19:14,070 and it's nice to assign them to a known state, 508 00:19:14,070 --> 00:19:15,570 in this case an unknown state. 509 00:19:15,570 --> 00:19:17,730 So that's that, then we've got a sequence 510 00:19:17,730 --> 00:19:19,860 which is the Abort sequence, the Hold sequence, 511 00:19:19,860 --> 00:19:21,300 or the Launch sequence. 512 00:19:21,300 --> 00:19:22,980 Depending on what the state is, 513 00:19:22,980 --> 00:19:25,170 we execute a specific sequence. 514 00:19:25,170 --> 00:19:26,220 So what we've done here 515 00:19:26,220 --> 00:19:29,247 is we've got our stream extraction operator 516 00:19:29,247 --> 00:19:30,810 now that we've overloaded 517 00:19:30,810 --> 00:19:31,650 and this is pretty neat 518 00:19:31,650 --> 00:19:34,470 because it allows the user to enter something, 519 00:19:34,470 --> 00:19:37,560 and we're gonna create a state variable from it. 520 00:19:37,560 --> 00:19:40,320 So in this case, we're gonna use the underlying type 521 00:19:40,320 --> 00:19:41,850 and you can see that right there. 522 00:19:41,850 --> 00:19:43,380 That's the underlying type. 523 00:19:43,380 --> 00:19:44,790 We know that the underlying type 524 00:19:44,790 --> 00:19:46,890 for this enumeration is an int. 525 00:19:46,890 --> 00:19:49,860 We could have used int user_input just like this, 526 00:19:49,860 --> 00:19:51,780 but it's much better to use the underlying type 527 00:19:51,780 --> 00:19:54,480 because it could change in the future if someone 528 00:19:54,480 --> 00:19:57,120 assigns some initial enumerator value 529 00:19:57,120 --> 00:19:59,220 to one of those things that's not an int 530 00:19:59,220 --> 00:20:02,730 and what we're doing is we're reading that user_input 531 00:20:02,730 --> 00:20:04,830 from the input stream. 532 00:20:04,830 --> 00:20:06,450 We're switching on it 533 00:20:06,450 --> 00:20:07,800 and depending on what it is, 534 00:20:07,800 --> 00:20:10,050 in this case, if it's one of those things 535 00:20:10,050 --> 00:20:11,400 that we know about, right? 536 00:20:11,400 --> 00:20:14,490 Engine failure, Inclement_Weather, Nominal or Unknown, 537 00:20:14,490 --> 00:20:18,180 we're casting that user input to a State type 538 00:20:18,180 --> 00:20:21,000 and assigning it to state which is that guy right there. 539 00:20:21,000 --> 00:20:23,520 Otherwise we're gonna assign it to the state Unknown 540 00:20:23,520 --> 00:20:25,830 because they've obviously entered something else 541 00:20:25,830 --> 00:20:28,470 and the idea being if it's in an Unknown state, 542 00:20:28,470 --> 00:20:30,840 we're not gonna launch this rocket, we're gonna abort. 543 00:20:30,840 --> 00:20:33,180 So we've got those three sequences you can see up here, 544 00:20:33,180 --> 00:20:34,950 Abort, Hold, and Launch. 545 00:20:34,950 --> 00:20:38,430 Here we're overloading the string insertion operator 546 00:20:38,430 --> 00:20:39,630 just like we did before, 547 00:20:40,800 --> 00:20:42,090 but for sequence in this case. 548 00:20:42,090 --> 00:20:43,590 So given a sequence, 549 00:20:43,590 --> 00:20:47,220 if it's abort, we're just going to display Abort, Hold, 550 00:20:47,220 --> 00:20:50,310 or Launch depending on what the enumerator value is. 551 00:20:50,310 --> 00:20:52,260 And then in the case of initiate 552 00:20:52,260 --> 00:20:54,240 when we're calling initiate with a sequence, 553 00:20:54,240 --> 00:20:57,090 it's just gonna display the sequence that's being initiated 554 00:20:57,090 --> 00:20:58,440 just so we can actually see it. 555 00:20:58,440 --> 00:20:59,490 And this is going to use 556 00:20:59,490 --> 00:21:03,093 the overloaded stream insertion operator right there. 557 00:21:04,200 --> 00:21:05,400 Okay, so here's test three. 558 00:21:05,400 --> 00:21:07,350 So take a look at this, it's pretty straightforward. 559 00:21:07,350 --> 00:21:09,400 I'm creating my state variable right here 560 00:21:10,260 --> 00:21:12,510 and I'm reading that from the user. 561 00:21:12,510 --> 00:21:14,880 Now this is using our extraction operator 562 00:21:14,880 --> 00:21:16,110 that we just overloaded. 563 00:21:16,110 --> 00:21:17,370 You can see how neat this is 564 00:21:17,370 --> 00:21:21,900 because this feels just like anything else in C++, right? 565 00:21:21,900 --> 00:21:23,160 This is how we read integers. 566 00:21:23,160 --> 00:21:24,480 This is how we read strings. 567 00:21:24,480 --> 00:21:26,340 This is how we read a lot of things. 568 00:21:26,340 --> 00:21:30,180 However this is a user-defined type that we created, state, 569 00:21:30,180 --> 00:21:33,090 so we have to overload the extraction operator 570 00:21:33,090 --> 00:21:35,400 so that we can write code like this. 571 00:21:35,400 --> 00:21:38,160 Depending on whatever stake the user entered, 572 00:21:38,160 --> 00:21:40,620 if they entered Engine_Failure 573 00:21:40,620 --> 00:21:42,120 or if it's Unknown, right? 574 00:21:42,120 --> 00:21:43,320 They entered something else, 575 00:21:43,320 --> 00:21:46,050 we're going to initiate the abort sequence. 576 00:21:46,050 --> 00:21:48,090 If it's Inclement_Weather, we're gonna hold 577 00:21:48,090 --> 00:21:50,610 and if it's Nominal, we're going to launch. 578 00:21:50,610 --> 00:21:52,110 So let's run this 579 00:21:52,110 --> 00:21:54,850 and I'll put in a zero which is Engine_Failure 580 00:21:54,850 --> 00:21:56,850 and we're initiating the Abort sequence, right? 581 00:21:56,850 --> 00:21:57,750 That's what we want. 582 00:21:57,750 --> 00:21:58,890 So let's try it with another one. 583 00:21:58,890 --> 00:22:00,060 Let's run it again. 584 00:22:00,060 --> 00:22:02,800 In this case, we'll put in a one 585 00:22:03,660 --> 00:22:06,120 and we're holding because one is Inclement_Weather. 586 00:22:06,120 --> 00:22:09,180 That's pretty cool, let's try it again. 587 00:22:09,180 --> 00:22:10,690 Let's put in a two this time 588 00:22:11,700 --> 00:22:13,560 and let me move this over here. 589 00:22:13,560 --> 00:22:16,170 We're gonna put in a two, we're launching, right? 590 00:22:16,170 --> 00:22:18,363 Because two is Nominal. 591 00:22:19,200 --> 00:22:21,660 And now let's put in something like 100 or something, right? 592 00:22:21,660 --> 00:22:23,280 Something that's definitely not 593 00:22:23,280 --> 00:22:26,310 a valid enumerator for the estate. 594 00:22:26,310 --> 00:22:28,178 So let's run this 595 00:22:28,178 --> 00:22:29,580 and let's put in 100, 596 00:22:29,580 --> 00:22:31,593 and what we want is we want to abort. 597 00:22:33,300 --> 00:22:34,620 And that's exactly what we get. 598 00:22:34,620 --> 00:22:36,510 The user input is not a valid launch state, 599 00:22:36,510 --> 00:22:38,970 so what we're doing is we're setting the state to Unknown 600 00:22:38,970 --> 00:22:41,580 which it initiates that Abort sequence right here. 601 00:22:41,580 --> 00:22:42,630 This is all well and good, 602 00:22:42,630 --> 00:22:44,550 but what's really important that you understand 603 00:22:44,550 --> 00:22:46,260 is look at that code. 604 00:22:46,260 --> 00:22:48,060 Look how readable this is. 605 00:22:48,060 --> 00:22:49,380 We're switching on the state. 606 00:22:49,380 --> 00:22:51,780 If it's Engine_Failure, Unknown, we initiate Abort. 607 00:22:51,780 --> 00:22:54,810 We're using these enumerators which is so important. 608 00:22:54,810 --> 00:22:57,420 Instead of just having magic numbers 609 00:22:57,420 --> 00:22:59,190 and all kinds of weird things in our code 610 00:22:59,190 --> 00:23:02,580 that make things very, very difficult to understand. 611 00:23:02,580 --> 00:23:05,310 Okay, so I encourage you to play around with this code, 612 00:23:05,310 --> 00:23:07,500 change things around, understand it. 613 00:23:07,500 --> 00:23:09,690 The best way to learn this is just to get in that code 614 00:23:09,690 --> 00:23:12,120 and fiddle with it, and change it around a little bit, 615 00:23:12,120 --> 00:23:13,320 and add some new states, 616 00:23:13,320 --> 00:23:14,730 and try different things. 617 00:23:14,730 --> 00:23:15,870 In the next video, 618 00:23:15,870 --> 00:23:18,930 what we'll do is we'll talk about scoped enumerations 619 00:23:18,930 --> 00:23:21,203 and we'll see how much better they actually are.