In this lecture you will learn about the Enumerations in C++, so find a way to provide the constants
is to use an enum value.
So in effect, an enemy is a group of named constants, which means that you can use an enum as a parameter
to function.
So for example, let's call the.
Cards here.
Klopp's.
Silence.
Part.
Space.
Actually, let's look at cards with sweets here.
Sweets.
So this defines an enumeration called suites with named values for the suites in a deck of cards.
So an enumeration is an integer type, and by default, the compiler will assume an integer.
But you can change this by specifying the integer type in the declaration.
So there are just four possible values for cards.
So it's it's a waste memory to use integer usually for bytes, and instead we can use character as a
single byte.
So let's make a character.
So it's here and our double dots here.
Car clubs.
Here.
Diamonds.
Beer charts.
Here's Speights.
Speights Yeah, So as you can see, we have a switch here, so it's character.
It's name it.
And as you can see here, Enumeration Valley Club.
So we have this same value.
We can't have same values in here.
So my clubs.
These are my diamonds.
They're my hearts and my space.
So when you use an enumerated value, you can use just name, however it's serial to scope it with this
name of enumeration.
So it will make the code more readable.
So for example, suites card card one equals diamonds.
So it's card two equals.
So it's, for example, spades.
Spence.
Yeah.
So what forms are aloft?
They are the same, but the latter makes it more explicit that the value is taken from an enumeration.
So to first of all, specify the scope.
You can apply the keyword class here in animal after in here, for example, class.
As you can see here in the plot, the class here we now obligated to add and mention the enum type before
we choose this.
And the cleared values.
So as you can see, we got an error here.
If we delete the class, this both codes will work in this example.
So actually I will add comment as this so you can test it in your computer class.
And here.
So let's compile our application, see if we have any errors.
As you can see, we don't have any errors here.
So with this definition here, this car to the line decline, car two will compile.
But the line declaring card one, as you can see here, will not so.
With the scope scoped enum.
Here, the compiler treats the enumeration as a new type and has no inbuilt conversion for your new
type to an integer variable.
For example, let's create an.
Character.
Actually common common for now.
And the common is to.
Character C equals card plus ten.
As you can see here, this is the undeclared identifier card.
When we compile this card was not clear in this scope, do we?
Did you mean card two?
Let's start.
Card two.
And as you can see here, we get an error two, because we just want to use card card here.
So in order to do this.
As you can see here.
So it's card here.
So it's card equals six diamonds.
Here.
And see card plus ten.
So we get an error here.
As you can see here.
Now, I will explain why we got an error here.
So that's because.
The end type is based on character.
But when you define the suite's variable as being scoped with class here, as you can see here, the
second line will not compile.
If the enumeration is defined as not being scoped without class here, without class, then there is
an inbuilt conversion between the enumerated value and character.
Yes.
So let's select class.
And as you can see, we got no errors anymore and our code compiles successfully.
So by default the compiler will give the first enumerator a value of zero.
So and then increment the value by the subsequent enumeration enumerators.
So does the suite's diamonds.
Yes.
So it's diamonds will have value one because it's the second value in suits.
And here.
So you can assign values yourself to.
So, for example, let's get another enumeration type a new car brands and car brands.
Okay.
So then let's add.
So, for example, BMW, BMW.
Let's make it 100 B or MERCEDEZ MERCEDEZ here, 200.
For example, Fiat here.
300.
Your Volkswagen.
400.
And the.
Let's make another car.
Name.
You're.
Mhm.
I forget the car names here.
So we're in out here, 999 or 909,009 here.
Make it that way.
So in this case.
The BMW has value of 700, the white BMW has value of hundred, Mercedes 200, Fiat 300.
Volkswagen 400 and renowned 9999.
And in this case here, as you can see, we assigned values.
So there are no longer, no longer this, for example, my class equals zero.
And as you can see, this value is one.
As you can see here, value is.
Three two here, as you can see.
And value is not a tree here.
So when you select this, you will see the value of 909,999.
Here.
As you can see here.
Value is 400, as you can see here.
So enumerations are useful in a switch statement, which you will see later in this course, because
the named value makes it clearer than using just an integer.
So you can also use an enumeration as a parameter to find a function and hence restrict the values based
via parameter.
So now I want to create a function with it.
For example, void stack and.
You can pass parameters, for example, as car brands, suites and other named enumeration.
So in next lecture, we're going to declare we're going to go depth into the pointers and namespaces.
So I'm waiting you in the next lecture.