CLASSES vs STRUCTS in C++

preview_player
Показать описание


Рекомендации по теме
Комментарии
Автор

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.

poipoi
Автор

#define struct class


yeah that's not going to confuse anybody

zperk
Автор

To elaborate more on what Cherno says in this video, structs are a legacy feature from C which can group together variables into a user-defined type, BUT CANNOT contain functions (because C did not have OOP features such as methods).

This is why it's common in C++ to use structs for "classes with no methods", because that was how they were used in C.

Reydriel
Автор

For anyone struggling with: #define struct class

Basically what he did there is he told the compiler to treat "struct" as a "class".
For example u could do same thing to types like this: #define INTEGER int

And you still could instatiate "INTEGER" the same way you would do it for ""int".

INTEGER a = 8;

is same as:

int a = 8;

Hope that explains it.

Ivan-xwpr
Автор

I have seen every video up to now and they help me very much to refresh my out-dated C++ knowledge

manfredkernMK
Автор

Subtitles again, "Hey little guys and my name is Machado and welcome to my people of clock series"

jamesmnguyen
Автор

the auto generation captions are hilarious
"he little guys my name is Machado and welcome back to my people of clock series"

alionking
Автор

I just realized you were talking about inheritance and I remember what it was like all those years ago when I first heard the word.
Most people feel the same way: What in the world is inheritance?

Inheritance is probably one of the most useful benefits to classes you have available to you, to allow a class to "inherit" the public members and methods of another class.
They also allow for virtual methods in the base class that all inherited classes has the option of overloading (basically means to re-define), to give them unique functionality.
They are incredibly powerful, and I cannot imagine a world without them.

We use them everywhere in c#, I assume c++ is no different.

squg
Автор

This is a WONDERFUL series. I'll definitely be supporting on patreon

RathFGC
Автор

I'm coming from the world of C#, and I remember that in C#, classes are reference types while structs are value types.

BackerSultan
Автор

I see some people stating that one additional "difference" between structs and classes is that the structs are stack-allocated and classes are heap allocated. This may be true in languages like C#, however in C++ you may allocate classes (objects, actually) and structs in either the stack or the heap, it's just done differently in code (to allocate on the heap, you use the keyword "new").
You may as well have stack-allocated classes and heap-allocated structs; as Cherno says, there are very few rules in C++ when it comes down to it.

luxxsolari
Автор

every time I watch a video on your channel, I learn something new that sticks in my head forever.
#Define struct class. That one is mind-blowing!

codingwithelhacen
Автор

The C++ Core Guidelines C.2 states: "Use class if the class has an invariant; use struct if the data members can vary independently."

So if you don't have any preexisting style, your best bet is to stick to that.

TheReficul
Автор

Hey Cherno, would you mind making an episode explaiing a bit how char, char static arrays, char dynamic arrays, strings, string arrays etc. work in C++ and when to use which one? I've always found this whole confusion very difficult to deal with.

nanithefk
Автор

After so many years just learned that structs in C++ can have functions. May have seen this in code many times, but never thought they were structs.

fazillatheef
Автор

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

roja
Автор

I am addicted to learning c++ right now thanks to you.

msidc
Автор

Just learning C++ again .... Spending time understanding the nuances is paying off. Useful vid.

steve_rico
Автор

Currently trying to wrap my hand around structs and this video clarified way more than cppreference, SO or w3

ajoshdoingthings
Автор

Dude, thank you so much holy hell--I've been looking all morning.

oasishurl