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

45 thoughts on “CLASSES vs STRUCTS in C++

  • January 1, 2021 at 1:12 am
    Permalink

    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)

  • January 3, 2021 at 3:41 am
    Permalink

    OMG!! I would like to like this video 10 times but unfortunately, it's not possible!

    Such a useful video, Thanks so much!

  • January 22, 2021 at 1:10 am
    Permalink

    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

  • January 29, 2021 at 8:04 pm
    Permalink

    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.

  • January 30, 2021 at 2:36 pm
    Permalink

    So to summarize: a struct is just the class' little brother whom doesn't have to take as much responsibility.

  • February 4, 2021 at 8:11 pm
    Permalink

    i always use classes now because i think its easyer to only use one

  • February 4, 2021 at 10:39 pm
    Permalink

    Nice explanation! I do love how your channel covers C++ so well, it's hard to find good channels about this.

  • February 14, 2021 at 1:43 am
    Permalink

    I rewritten my code to is struct instead of class and my code now runs faster x7 times. Wtf… Is using class too slow?

  • February 20, 2021 at 4:57 pm
    Permalink

    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.

  • March 6, 2021 at 11:40 am
    Permalink

    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.

  • March 18, 2021 at 6:31 am
    Permalink

    Cherno, can you recommend me a c++ book? For beginners if possible..

  • March 23, 2021 at 12:56 am
    Permalink

    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.

  • March 31, 2021 at 10:09 am
    Permalink

    it finally makes sense to me now that I understand that structs in c++ are massively different and upgraded from structs in C lol

  • May 23, 2021 at 12:59 pm
    Permalink

    In C#, the struct becomes very strict, like you can't do inheritance. Maybe because Microsoft's workers had watch this video.

  • May 23, 2021 at 12:59 pm
    Permalink

    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)

  • June 14, 2021 at 9:29 pm
    Permalink

    You could be asking for trouble when you make your member public.

  • July 8, 2021 at 7:05 pm
    Permalink

    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.

  • July 13, 2021 at 1:47 am
    Permalink

    So that you realize how nice a teacher he is, I actually can say no to Fifa (video game) and watch his tutorials instead.

  • July 17, 2021 at 10:40 pm
    Permalink

    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

  • July 21, 2021 at 7:10 pm
    Permalink

    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

  • August 17, 2021 at 1:54 pm
    Permalink

    The funny thing is I've been learning C++ for 3 years and I've never used a struct before. Only classes

  • August 24, 2021 at 11:53 pm
    Permalink

    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)

  • September 12, 2021 at 8:30 pm
    Permalink

    what is the piano music in the beginning?
    sounds amazing!!!

  • September 19, 2021 at 12:19 pm
    Permalink

    Are memory allocation same for classes and structures ? Is there any difference when allocating memory inside each

  • September 25, 2021 at 9:58 pm
    Permalink

    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?

  • October 12, 2021 at 9:08 pm
    Permalink

    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??? 😅😅

  • October 19, 2021 at 5:56 pm
    Permalink

    If we can convert struct into a class with #define then how many more keywords can we manipulate like this?? :0

  • October 28, 2021 at 7:58 am
    Permalink

    Nope, but I'll let you find the other difference, I'll help you: it's about passing different variable types

  • December 8, 2021 at 12:14 am
    Permalink

    struct= kind of primitive value, class = relation and behaviours

  • December 11, 2021 at 11:50 pm
    Permalink

    Commenting for your exposure. The best channel on YouTube for C++ !!!

Leave a Reply

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