1 00:00:00,710 --> 00:00:08,180 In this lecture you will learn about the Enumerations in C++, so find a way to provide the constants 2 00:00:08,180 --> 00:00:10,990 is to use an enum value. 3 00:00:11,000 --> 00:00:19,190 So in effect, an enemy is a group of named constants, which means that you can use an enum as a parameter 4 00:00:19,190 --> 00:00:20,080 to function. 5 00:00:20,090 --> 00:00:23,000 So for example, let's call the. 6 00:00:24,660 --> 00:00:26,010 Cards here. 7 00:00:27,200 --> 00:00:28,130 Klopp's. 8 00:00:29,060 --> 00:00:29,930 Silence. 9 00:00:30,900 --> 00:00:31,590 Part. 10 00:00:32,670 --> 00:00:33,540 Space. 11 00:00:33,750 --> 00:00:37,880 Actually, let's look at cards with sweets here. 12 00:00:37,890 --> 00:00:38,550 Sweets. 13 00:00:38,700 --> 00:00:48,090 So this defines an enumeration called suites with named values for the suites in a deck of cards. 14 00:00:48,090 --> 00:00:54,990 So an enumeration is an integer type, and by default, the compiler will assume an integer. 15 00:00:54,990 --> 00:00:59,600 But you can change this by specifying the integer type in the declaration. 16 00:00:59,610 --> 00:01:02,600 So there are just four possible values for cards. 17 00:01:02,610 --> 00:01:10,290 So it's it's a waste memory to use integer usually for bytes, and instead we can use character as a 18 00:01:10,290 --> 00:01:11,870 single byte. 19 00:01:11,880 --> 00:01:14,670 So let's make a character. 20 00:01:14,670 --> 00:01:19,920 So it's here and our double dots here. 21 00:01:20,190 --> 00:01:21,750 Car clubs. 22 00:01:22,630 --> 00:01:23,290 Here. 23 00:01:23,890 --> 00:01:24,790 Diamonds. 24 00:01:25,670 --> 00:01:27,680 Beer charts. 25 00:01:29,210 --> 00:01:31,700 Here's Speights. 26 00:01:32,990 --> 00:01:38,780 Speights Yeah, So as you can see, we have a switch here, so it's character. 27 00:01:39,850 --> 00:01:40,430 It's name it. 28 00:01:40,430 --> 00:01:44,090 And as you can see here, Enumeration Valley Club. 29 00:01:44,090 --> 00:01:46,310 So we have this same value. 30 00:01:46,340 --> 00:01:49,340 We can't have same values in here. 31 00:01:49,370 --> 00:01:52,250 So my clubs. 32 00:01:53,050 --> 00:01:56,680 These are my diamonds. 33 00:01:57,460 --> 00:02:02,260 They're my hearts and my space. 34 00:02:03,100 --> 00:02:10,960 So when you use an enumerated value, you can use just name, however it's serial to scope it with this 35 00:02:10,960 --> 00:02:12,700 name of enumeration. 36 00:02:13,180 --> 00:02:16,340 So it will make the code more readable. 37 00:02:16,360 --> 00:02:22,870 So for example, suites card card one equals diamonds. 38 00:02:24,550 --> 00:02:28,270 So it's card two equals. 39 00:02:28,570 --> 00:02:32,050 So it's, for example, spades. 40 00:02:33,360 --> 00:02:34,140 Spence. 41 00:02:35,390 --> 00:02:35,820 Yeah. 42 00:02:36,080 --> 00:02:38,720 So what forms are aloft? 43 00:02:38,750 --> 00:02:45,920 They are the same, but the latter makes it more explicit that the value is taken from an enumeration. 44 00:02:45,920 --> 00:02:48,580 So to first of all, specify the scope. 45 00:02:48,590 --> 00:02:59,360 You can apply the keyword class here in animal after in here, for example, class. 46 00:02:59,840 --> 00:03:11,270 As you can see here in the plot, the class here we now obligated to add and mention the enum type before 47 00:03:12,170 --> 00:03:13,370 we choose this. 48 00:03:14,600 --> 00:03:15,980 And the cleared values. 49 00:03:16,490 --> 00:03:18,680 So as you can see, we got an error here. 50 00:03:18,680 --> 00:03:24,020 If we delete the class, this both codes will work in this example. 51 00:03:24,590 --> 00:03:30,560 So actually I will add comment as this so you can test it in your computer class. 52 00:03:30,560 --> 00:03:32,390 And here. 53 00:03:32,390 --> 00:03:36,980 So let's compile our application, see if we have any errors. 54 00:03:36,980 --> 00:03:39,840 As you can see, we don't have any errors here. 55 00:03:39,860 --> 00:03:50,810 So with this definition here, this car to the line decline, car two will compile. 56 00:03:50,930 --> 00:03:58,190 But the line declaring card one, as you can see here, will not so. 57 00:03:59,390 --> 00:04:01,740 With the scope scoped enum. 58 00:04:01,760 --> 00:04:09,290 Here, the compiler treats the enumeration as a new type and has no inbuilt conversion for your new 59 00:04:09,320 --> 00:04:10,970 type to an integer variable. 60 00:04:11,000 --> 00:04:12,980 For example, let's create an. 61 00:04:17,370 --> 00:04:18,180 Character. 62 00:04:19,680 --> 00:04:22,500 Actually common common for now. 63 00:04:22,980 --> 00:04:25,230 And the common is to. 64 00:04:26,550 --> 00:04:30,420 Character C equals card plus ten. 65 00:04:33,050 --> 00:04:36,450 As you can see here, this is the undeclared identifier card. 66 00:04:36,470 --> 00:04:41,560 When we compile this card was not clear in this scope, do we? 67 00:04:41,720 --> 00:04:42,890 Did you mean card two? 68 00:04:42,920 --> 00:04:44,300 Let's start. 69 00:04:44,300 --> 00:04:45,320 Card two. 70 00:04:45,650 --> 00:04:52,460 And as you can see here, we get an error two, because we just want to use card card here. 71 00:04:52,610 --> 00:04:55,370 So in order to do this. 72 00:04:56,580 --> 00:04:57,900 As you can see here. 73 00:04:58,800 --> 00:05:01,830 So it's card here. 74 00:05:02,430 --> 00:05:06,900 So it's card equals six diamonds. 75 00:05:08,300 --> 00:05:08,800 Here. 76 00:05:10,030 --> 00:05:13,230 And see card plus ten. 77 00:05:13,240 --> 00:05:14,980 So we get an error here. 78 00:05:16,190 --> 00:05:17,270 As you can see here. 79 00:05:17,270 --> 00:05:20,360 Now, I will explain why we got an error here. 80 00:05:20,360 --> 00:05:22,280 So that's because. 81 00:05:23,140 --> 00:05:26,590 The end type is based on character. 82 00:05:26,830 --> 00:05:33,850 But when you define the suite's variable as being scoped with class here, as you can see here, the 83 00:05:33,850 --> 00:05:35,440 second line will not compile. 84 00:05:35,800 --> 00:05:45,430 If the enumeration is defined as not being scoped without class here, without class, then there is 85 00:05:45,430 --> 00:05:49,690 an inbuilt conversion between the enumerated value and character. 86 00:05:49,720 --> 00:05:50,290 Yes. 87 00:05:51,070 --> 00:05:53,020 So let's select class. 88 00:05:53,020 --> 00:05:58,690 And as you can see, we got no errors anymore and our code compiles successfully. 89 00:05:58,690 --> 00:06:04,390 So by default the compiler will give the first enumerator a value of zero. 90 00:06:05,140 --> 00:06:09,810 So and then increment the value by the subsequent enumeration enumerators. 91 00:06:09,820 --> 00:06:13,700 So does the suite's diamonds. 92 00:06:13,720 --> 00:06:14,230 Yes. 93 00:06:14,260 --> 00:06:22,950 So it's diamonds will have value one because it's the second value in suits. 94 00:06:22,960 --> 00:06:23,830 And here. 95 00:06:24,130 --> 00:06:27,610 So you can assign values yourself to. 96 00:06:27,640 --> 00:06:36,430 So, for example, let's get another enumeration type a new car brands and car brands. 97 00:06:37,240 --> 00:06:38,080 Okay. 98 00:06:38,200 --> 00:06:40,030 So then let's add. 99 00:06:40,390 --> 00:06:44,170 So, for example, BMW, BMW. 100 00:06:44,260 --> 00:06:55,330 Let's make it 100 B or MERCEDEZ MERCEDEZ here, 200. 101 00:06:56,890 --> 00:06:59,530 For example, Fiat here. 102 00:07:00,900 --> 00:07:01,860 300. 103 00:07:01,890 --> 00:07:03,180 Your Volkswagen. 104 00:07:04,320 --> 00:07:05,340 400. 105 00:07:06,170 --> 00:07:07,290 And the. 106 00:07:08,800 --> 00:07:10,780 Let's make another car. 107 00:07:10,870 --> 00:07:11,410 Name. 108 00:07:15,130 --> 00:07:15,820 You're. 109 00:07:16,850 --> 00:07:17,160 Mhm. 110 00:07:17,930 --> 00:07:19,610 I forget the car names here. 111 00:07:24,630 --> 00:07:30,060 So we're in out here, 999 or 909,009 here. 112 00:07:30,090 --> 00:07:31,590 Make it that way. 113 00:07:32,280 --> 00:07:34,620 So in this case. 114 00:07:35,590 --> 00:07:46,110 The BMW has value of 700, the white BMW has value of hundred, Mercedes 200, Fiat 300. 115 00:07:46,120 --> 00:07:50,560 Volkswagen 400 and renowned 9999. 116 00:07:51,220 --> 00:07:55,840 And in this case here, as you can see, we assigned values. 117 00:07:55,840 --> 00:08:02,380 So there are no longer, no longer this, for example, my class equals zero. 118 00:08:02,530 --> 00:08:05,980 And as you can see, this value is one. 119 00:08:05,980 --> 00:08:09,910 As you can see here, value is. 120 00:08:11,530 --> 00:08:14,140 Three two here, as you can see. 121 00:08:14,170 --> 00:08:18,310 And value is not a tree here. 122 00:08:18,310 --> 00:08:27,040 So when you select this, you will see the value of 909,999. 123 00:08:28,820 --> 00:08:29,480 Here. 124 00:08:31,490 --> 00:08:32,660 As you can see here. 125 00:08:33,700 --> 00:08:37,810 Value is 400, as you can see here. 126 00:08:38,110 --> 00:08:46,510 So enumerations are useful in a switch statement, which you will see later in this course, because 127 00:08:46,510 --> 00:08:50,030 the named value makes it clearer than using just an integer. 128 00:08:50,050 --> 00:08:57,450 So you can also use an enumeration as a parameter to find a function and hence restrict the values based 129 00:08:57,460 --> 00:08:59,020 via parameter. 130 00:08:59,050 --> 00:09:02,950 So now I want to create a function with it. 131 00:09:03,550 --> 00:09:07,120 For example, void stack and. 132 00:09:08,990 --> 00:09:16,370 You can pass parameters, for example, as car brands, suites and other named enumeration. 133 00:09:16,400 --> 00:09:24,440 So in next lecture, we're going to declare we're going to go depth into the pointers and namespaces. 134 00:09:24,440 --> 00:09:26,990 So I'm waiting you in the next lecture.