What are ENUMS in C++ | Top Latest 2021

ENUMS in C++

Today I’m going to be talking about ENUMS in C++ you know and save us plus so enormous short for enumeration and basically all it is a set of values if you want a more practical definition than the old Minami is a way to give a name to a face value Sir instead of having a bunch of images called A. T. C. we can happen venom which has the values a B. savers correspondences it also helps us to find a set of values so that instead of just having an integer as a type which of course you could assign any need to tear you limit which values can be assigned to what so without complicating things that’s really old it is it’s just a way to name values it’s very useful when you want to use integers to represent 7 states also in values however you want to give them a name so that your card is more readable at the end of the day in venom he’s just in nature however in your card it looks a little bit different and it helps to keep your car to be cleaned up let’s dive in and take a look suppose that I have 3 values that I want to take care off I had to pay which I might set to 0 B. ENUMS in C++ ENUMS in C++

Which on my set one and state which on my sister so I have 3 values take cero and then somewhere in Maine on might use my value and I might set a call to one of these 3 letter on my card I might have some courage check what the current value is and then perform some sort of action this is fine however carries a few issues first of all these A. B. C.’s Arnold group at all somewhere later in your car you might have I DO you want to declare again and suddenly this is a bit of an issue but essentially the biggest problem here is that these on approved at all for the more than just into just meaning I can assign something like 5 here and suddenly this doesn’t make any sense anymore we want to be able to essentially define a type which can only be one of these 3 there’s also groups in some kind of fashion which is exactly what items can be useful so instead of this I can have my venom which awful example and then I can list off which values I want to have here such as a Beatle St instead of having an interest my time I can.  ENUMS in C++ ENUMS in C++

Now use the email name as an actual time so I can write example value I’m going to change my mind it’s just to be lower case here just so that I can use my number is probably and you can see that I can assign a value just like this if I try to find something else I’ll get an arrow because it has to be 1 of bass 3 now these are just into just at the end of the day keep that in mind I can still do a check if I if I read this back to be I could still do it checks such as value equals 1 because the does carry the value 1 if you have your mouse over this it’ll even tell you to be as 1 you can actually specify the value of each of these parables wealthy darn by default the first 1 will be easier and then it will increments 1 by 1 to specify a value just had equal to something so I can have this is the error this is true this is fixed whatever you really want if you stop from a number that is non 0 such as 5 and you George actually specify the rest of these values you can say that this will be 6 minutes. ENUMS in C++ ENUMS in C++

We’ll be 7 because it will basically just stop from 5 and then keep going up 1 thing that you can also do is specify which type of industry you want to say not to be and even this I’ve already had a call in and then the daughters 5 so for example an online shop in almost by default 32 bit integers however you can see in this case there’s no need for us to use that there should be a value we can we get away with using an 8 bit into shop such as an online shop and would be just fine and suddenly it’s taking way less memory you won’t be able to assign this to something like a Florida of course because the flight isn’t an integer and it has to be an integer Leslie this either China for example so then we are that’s basically what I mean I mean it’s just a way to give a name to set values so that you don’t have to keep dealing with indigenous and be all over the place let’s take a look at a real world example of the way you might use in a non by looking at a low class that we started riding in the how to write essay plus loss if we don’t hurry here to a low class because he will we actually ended up doing was using 3 different local levels and they would just integers here 012 hopefully you can see this is pretty much a perfect candidate for any non because we have 3.  ENUMS in C++ ENUMS in C++

I use which we just used as integers to represent a 7 state in this case which local level out local actually display SO rider here inside this low class I’m going to create a level income I’m going to create era warning and inferred values considered wasting mirroring this as a matter of style I actually like to explicitly right equals there are however that’s definitely not required because it will stop at 0 by default but again just something I like doing to help the readability the card I’ll get rid of these now instead of having an incest my low level which I could still have of course ENUMS in C++ ENUMS in C++ I could still find it in far and since any numbers just in into this would still lack however in this case I would be able to set any value to low level any integer value to the lower level and I’d want to restricted just to just being base 3 so I will actually set this to be level not that this restriction that I’ve created of it must be it is these 3. Only a syntactical symbols plus kind of compiler in force I think you can get around it and really easily it’s not something that Khan physically be sad of course in this case out you know it’s just a full body to show it’s just 4 bytes of memory you can put anything you want into that memory however by setting a time to level you’re restricting the cards so to speak to actually are only allow levels contain myself level to take an eye level now. ENUMS in C++ ENUMS in C++

When I do these checks they will still work just fine I just need to change low level era to just be Arab because and low level is this in on time which is and into job I can still do comparisons between them which is very useful for things like this I’ll change this to say warning and I’ll change this to say in far the other thing that changes here is the local sound level instead of being logged out log level error which used to be that interject it now simply becomes log error because we haven’t you know value hold inside out a little bit namespace noted this in level is not a namespace in itself there is something called in on a class which we will talk about you know the Article however just the regulation on this level isn’t really nice face to con use it as one which means it is Errol wanting info simply exists inside this law class and your second that is one thing like warning as well and everything’s fine and now. ENUMS in C++ ENUMS in C++

You might’ve noticed error doesn’t actually work and it gives us an error the reason this is happening is because we actually have a function called eras wild soap same day after this deliberately to show you what happens if you have a conflicting name now in this case unfortunately that wouldn’t work because when we try to refer to things like Eric here does not for a friend to functional third we definitely con have something called Eric Fila unfortunately if you want to have a function with the same name so for now we can just add a level prefix to be venom which by the way is very common practice so we know exactly what we’re referring to since this name doesn’t really mean much in those kind of things also this able to level in far. This the level era this is a little warning and this level in far and now was that I need this I can get rid of this and just have a second level Arab if I run my card you can say that I would get the result that I expect well on the error responding of course because we’ve sent out a level to be so they are in arms just essentially exists to make our lives easier and to make our card clean out they are just need to just behind the scenes and you can use them pretty much anywhere you like and it’s just there are many uses for enormous which we will cover in future Articles will differ depending on the classes well in another Article but essentially whenever you have a set of values which you want to represent numerically and you know that’s probably the way you guys next time. ENUMS in C++ ENUMS in C++

Also See

what are Pointers in C++ | Top latest 2021

Leave a Comment

Your email address will not be published. Required fields are marked *