CLASSES vs STRUCTS in C++
[ad_1]
Twitter ► https://twitter.com/thecherno
Instagram ► https://instagram.com/thecherno
Patreon ► https://patreon.com/thecherno
Series Playlist ► https://www.youtube.com/playlist?list=PLlrATfBNZ98dudnM48yfGUldqGD0S4FFb
BEST laptop for programming! ► http://geni.us/pakTES
My FAVOURITE keyboard for programming! ► http://geni.us/zNhB
FAVOURITE monitors for programming! ► http://geni.us/Ig6KBq
MAIN Camera ► http://geni.us/t6xyDRO
MAIN Lens ► http://geni.us/xGoDWT
Second Camera ► http://geni.us/CYUQ
Microphone ► http://geni.us/wqO6g7K
Slack ► https://slack.thecherno.com
Stream ► http://www.twitch.tv/thecherno
Website ► http://www.thecherno.com
Facebook ► http://www.facebook.com/thecherno
[ad_2]
CLASSES vs STRUCTS in C++
#CLASSES #STRUCTS
Im new to c++ so this might be a stupid question, but a method is basically nothing else than a function within a class or structure, right?
Also: If you keep it really simple (by that i mean simple, as it would probably never ever be in "real" code) you could also substitute some classes with just functions, cant you? (void functions)
OMG!! I would like to like this video 10 times but unfortunately, it's not possible!
Such a useful video, Thanks so much!
/hi/
Hi
!hi!
&Hi&
So I come mainly from Swift, where class and struct are two rather different things. But my idea of what the difference should be, based on my background in swift, is that a class has identity and a struct does not. So struct Point { x: Int; y: Int } does not have identity, because two points with identical x and y values are in every aspect, identical. If I return you one or the other it doesn't really matter. It's a value type essentially.
A Player object: class Player { p: Point } even if it effectively holds the same data as the Point struct now effectively has identity when we think about it and will, in Swift, act as a reference type
Sooo basically EA/Activision would say they prefer classes set to mostly private, and whatever the artists needs to change that function would be set to public?
i.e. changing roughness, ao, normals set to private will make it impossible for the artists to manipulate their work unless they know how to program.
So to summarize: a struct is just the class' little brother whom doesn't have to take as much responsibility.
i always use classes now because i think its easyer to only use one
Nice explanation! I do love how your channel covers C++ so well, it's hard to find good channels about this.
I rewritten my code to is struct instead of class and my code now runs faster x7 times. Wtf… Is using class too slow?
I like to use structs inside unions to give the variables initial values without a constructor. If I used a class the extra public keyword makes it less of a one line solution.
Structs in general I think look cleaner in unions tbh.
I wonder why I am getting LK2019 if I create a header for the class
header file
class Player {
public:
int x, y;
int speed;
void Move(int , int );
};
cpp file
class Player {
public:
int x, y;
int speed;
void Move(int xa, int ya) {
x += xa * speed;
y += ya * speed;
};
};
in main mail I have #onclude header file. If I include cpp file, no issue.
But what about functions definitions ?
Cherno, can you recommend me a c++ book? For beginners if possible..
Gotta be honest. I've only ever used structs in C programming. Didn't even think about using them in C++. Good to know I wasn't missing anything.
it finally makes sense to me now that I understand that structs in c++ are massively different and upgraded from structs in C lol
Amazing content, he explained the difference very well!
Gold ❤
In C#, the struct becomes very strict, like you can't do inheritance. Maybe because Microsoft's workers had watch this video.
For me, classes are usually strong enough to have human-like responsibility
while struct is more like a drawer (maybe a smart drawer as you can add some functionality to it)
You could be asking for trouble when you make your member public.
thanks for your great video!
keep up the good work
thank you share~
I found this helpful. Thanks
When I was taking my first class on object oriented programming the teacher showed us classes and I was like "Oh so is this the same thing as a struct?" and she said no without explaining more. I'm glad to see this video lol.
Bro, can't believe you're giving this information for free. Thanks!
So that you realize how nice a teacher he is, I actually can say no to Fifa (video game) and watch his tutorials instead.
Yeah default visibility and
Struct has public only,
Class has public-private-protected
the rest are small differences and you dont need to know that
Watching this video because i just watched you Timing with Chrono and Benchmarking…
In the timing video , you used Struct and at Benchmarking , you used class xD
the simpeliste tutorial in this tutorial series
The funny thing is I've been learning C++ for 3 years and I've never used a struct before. Only classes
What about union ?
CLASSES vs UNION?
I wonder how the literal physical implementation in ASM differ from a struct to a class. I have a hunch that Structs might be more light in resources but thats just based off of that I know that C is more 'low level' than c++. but dont quote me on that. i guess that would depend on the compiler you are using. Would be neat to find out. all i know is z80 asm. (mostly)
what is the piano music in the beginning?
sounds amazing!!!
Are memory allocation same for classes and structures ? Is there any difference when allocating memory inside each
Wait. So c++ has classes making it an oop language. Structs are technically the same with classes. C has structs. But it doesn't have classes. But classes are the same with structs. Wat?
That's fuckng good
This may be kinda mad this to say. If class and struct are so interrelated (private, public) why would we still call C is not an object oriented programming language??? 😅😅
i love you
If we can convert struct into a class with #define then how many more keywords can we manipulate like this?? :0
Nope, but I'll let you find the other difference, I'll help you: it's about passing different variable types
Short answer – Use only class because it can do everything!!
bg sound is so loud can't concentrate on you
So… C does support OOP?… What?
struct= kind of primitive value, class = relation and behaviours
Commenting for your exposure. The best channel on YouTube for C++ !!!