Difference Between CLASSES and STRUCTS in C++ | Top Latest 2021

Classes and Structs

Today we are talking about Classes and Structs we have these 2 times in several spots the structure which is short for structure or a class and they might appear to be sort of similar and a lot of people that little confused about what the differences are exactly when you should be using US trucks when you should be using a class this article is going to address all that sorry the difference is this. There is basically non there is one small difference to do with visibility Sir last time when I talked about how we had a class having its members private by default which meant that if I was to do something like this however I did not declare this is public then we would get an error because you can say that it would tell us that the move method in the plaid Klaus is inaccessible because it’s been marked as private as default meaning only other methods inside this class can actually access that movement which is why we have to ride public here if we want to execute this card because of course when polling plant don’t move outside of the plane and that’s essentially where the difference comes in a class is private by default. Classes and Structs Classes and Structs Classes and Structs

difference

If you don’t specify any kind of visibility modify like I did here if you don’t just get rid of it and you don’t specify anything apple the default is private however with the strict the default is public that is the only difference between instructing the class technically and you can see over here not hard we get an error because again movies and accessible however if I change this to say strict player that’s which lives changed what class destruct old that’s a lot done this is all fine now and if I actually did want something to be private I would explicitly have to write private and then of course that takes us back to the same error that we got with a class that is the difference it’s incredibly simple. That’s really all there is to it however instead of just putting up a 2 minute article and just mentioning that I want to kind of talk about how we might be defining differences between those 2 whites because like they might not technically have much of a difference however the usage in card is actually going to death. Classes and Structs Classes and Structs

The only reason struck really even exists and see ++ is because of the backwards compatibility that it wants to maintain with Sadie because say car doesn’t have classes it does have structures there and if we were suddenly to White House this whole structure he was entirely then we would lose all compatibility because the compiler disabled list compiler wouldn’t or what strict walls of course he could fix that pretty easily by just using has to find so we could write something like have to find strict class right and then suddenly well that’s going to do is replace all about struggles with classes Sir in this case even though this card might look pretty simple I compile it you can see the suddenly we get that same Arab tiles made combo access inside across even the reviews that we use the word struck here because of course is replaced struck with the white class and then maybe yes we can get that kind of compatibility between say card and civil third back because ideally you should be able to go in to say hi to replace the what struck with class and then make it public and that would be it that would be down that there would be no more difference in that Adelson aren’t so then the difference kind of semantically and how people say it comes down to more or less the usage if there is no difference. Classes and Structs Classes and Structs

when do I use trucks buses class do I use a strict if I want all of my members to be public and I don’t want to have to write the wet public is it really that trivial and yes by the way it is actually that trivial and so because of that people kind of come out with their own definitions for what I think is trucks and B. and what I think I class should be however there is no aren’t really like that really is an R. like right or wrong answer it’s kind of up to your style of programming. Sorry this is my article let’s talk a little bit about myself programming and well I might use each time so I like to use strikes whenever possible when I’m basically talking about plain old Dada OPA or tape basically what I’m talking about some kind of structure which just represents variables a bunch of variables and that’s really all it’s a death toll a great example of this might be something like a mathematical back to class if I was to come over here and I wanted to make some kind of structure which just held the 2 flights together such as a back to you I might define it as instructed and just have my X. and Y. flights why because fundamentally this back to colossal struck to whatever you want to call it is back to structure he’s just a representation of 2 flights that’s what it is at its core it’s not supposed to really contain a massive amount of functionality like a plate glass might work might be having you might like a plant class might have a 3 D. modeling my handled rendering card fat Freddy model it might be handling like how the plan moves around the map and taking keyboard input and all of that.  Classes and Structs Classes and Structs

There’s just so much functionality that right where is what this is. Is just 2 variables and we’ve grouped them literally just for the reason of making a card easier to use that old but we don and of course that’s not to say that I’m not going to be adding methods to this I absolutely well I might add a method called ads which takes in a none of actor and then adds it to the current back to by doing something like this right but again what I’m doing here is I’m just manipulating these variables I’ve just added a function that will manipulate those variables but at the end of the day I’m still just talking about those 2 variables now host if you were really to bring me down and think about it really hot then you could argue that at the end of the day even the plate glass is just manipulating those variables however there’s a bit of a difference in terms of design because we’re talking about something that is massively more complicated the other scenario is inheritance I will never use inheritance with strikes if I get to the point where I’m actually going to have an entire class hierarchy or some kind of inheritance hierarchy. Classes and Structs Classes and Structs

I’m going to use a class for that because again inheritance is something that’s adding another level of complexity and I just want my structures to be structures of Dada that’s it and initially to that if you try makes those types there so for example you have a class called Hey and then a strong cold be wishing how it’s from a some compounds will give you warnings telling you that your inheriting from my class but you’re strapped there are some other kind of minor differences but again that is warning suddenly your card will still whack it’s just a bit of it so magical difference so that’s kind of my reasons for using a strict S. is a classified just want to represent some data in a structure I will use a strict but if I’ve gone and high class filled with functionality like a like a game wild or a play or something that additionally might have inheritance all of these all of these systems I’m going to use a class and again that’s how I personally differentiate between those 2 types that’s how a lot of people I’ve seen in the industry differentiate between.  Classes and Structs Classes and Structs

Those 2 types but again it’s better there is technically no difference about from that visibility you can use a strict wherever you can use class that they got work the same way how do you guys enjoyed this article or if you did please hit that like button of course you can follow me as well on Twitter and Instagram links will be in the description below are if you really like these articles and you want to support this series and see more than you can support me on Patreon.com forward slash the chatter and additionally to just supporting me and making sure that I can make more articles you’ll get access to Ellie trough as well as a discussion board what we talk about what actually goes into these articles interested in that check out the link in the below the page on a conflict that ends next time we’re going to continue on our journey as to what classes I’m going to talk about stuff like inheritance and look at some examples of existing card to see how you should be structuring of classes how you should be writing them and how we can use them in our cars. Classes and Structs Classes and Structs

Also See


What are ENUMS in C++ | Top Latest 2021

Leave a Comment

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