Комментарии:
Why the opperator , built like that. Bruh
Ответитьwhat about const const int const * a - I'm constantly getting problems with C--
Ответить🦷
Ответитьvolatile const int wat = 6969;
ОтветитьWhen I use mutable .. do I have to put the const as well when I call the function as a reference ?
ОтветитьAbsolutely the clearest explanation of const out there!
ОтветитьNote for people using C++20 or greater: There is also 'constexpr' for explicit compile time constants.
ОтветитьI don't even put that keyword in front of things until I'm pretty sure I'm not going to change it.
Otherwise it's MEANINGLESS
🖖🏻
too confusing
Ответитьlove you!
ОтветитьThe best video on the const keyword, and it's not even close. Good stuff!
ОтветитьWhen we gonna get a video on assembly.
Ответить"If you want both members to be pointers, you have to put the asterisk before every member" - this is why every programmer should immediately adopt my style of placing pointer asterisks on the name side instead of the type side! Then it works perfectly when you define multiple pointers on one line. Well, until you try to define a function that returns a pointer, then your asterisk doesn't know where it wants to be.
"We still need to mark the method as const, but we just want to touch this variable" - a good example of when this pops up a lot is in "on demand" situations, such as load-on-demand, where an object loads its data in the background the first time it is required. In such a case, it is usually necessary to modify the object from a const situation, even though the method itself is not really the purpose of the modification, just the reason it is needed.
My head hurts :D I think I've done too many of these videos today. Great job though.
ОтветитьSo... "const int a" creates a constant a of type int, but "const int* a" creates a variable a of type constant int*??? Whyyyyy c++? Whyyyy?
ОтветитьI've been programming for years, but these details are things I largely didn't know. Now I hope I can improve my coding patterns accordingly, but still need to figure if I'm understanding everything correctly.
Ответитьthis made me think of those late nite 'incontinence' commercials
Ответитьthese videos sadly are not for newbies like me :(
are more like for intermediate ppl.
you are a reason I fell in love with c++ language again, your c++ videos are simply awesome :)
Ответитьmy head spinning -> const ;)
Ответить3 times const made me not to watch the video till the end 😫
ОтветитьNeed help - using VS2019 - when Cherno enters code that will not compile, he gets a 'squiggly' under the error right away - how do I set that up?
Ответитьthis is a complete video I was looking for thanks sir.
ОтветитьConst is a promise. You tell something that it's gonna be constant and it's not going to change.
Ответитьsince people are still watching/commenting. A great example why const on member functions should be used.
map[ ] operator (as in dict["key"] = value. it's sometimes (depending on the implementation of map) not const. So this dict["kye"] = value would compile and work, until it doesn't because you just inserted >value< at "kye".
If you don't know the framework in&out, be const correct. This particular thing was taken from the yt-video: c++ bugs at facebook.
awesome! thank you!
Ответитьlove it
ОтветитьSuper helpful. Thank you!
ОтветитьLiterally amazing video, just answered all my questions about const (and more) in 12 minutes, you're a GANGSTER
Ответитьconst std::string cmmt = "Great video!";
ОтветитьAwesome!
ОтветитьUndefined behavior
Ответить**EASY MENTAL MODEL TO PERMANENTLY REMEMBER THESE**
think of '*' as boundary, whatever is in contact with const is meant to be constant
eg1: int const *ptr -> int const |*| ptr
eg2: const int *ptr -> const int |*| ptr
-> const is in contact with int only, and ptr is separated thanks to boundry '*', this means:
1. we can't modify int values
2. we can modify pointer
eg3: int * const ptr; -> int |*| const ptr
-> const is in contact with ptr while int is separated, this means:
1. we can't modify pointer.
2. we can modify int values.
Also You can read backwards as suggested by @Jean-Nay Mar
Your videos are good but you talk pretty fast.
ОтветитьPersonal notes:
- reading backwards helps understanding what is constant
- making a class method constant says that that method will not change any of the class member
- defining a function outside of the class and passing class instance as a constant reference makes sure that the instance won’t change. Thus, any method in that function must be const, otherwise you get error
Pretty clear, thank you.
It should be noted, if a global variable is declared as "const" or a variable is declared "static const", then it is placed by the linker into a non writable CODE or CONST segment. When it is written to by some pointer trickery, an access violation exception will probably happen.
I spent like 20 minutes and then looked you up🤯🤯🤯! Thanks
Ответитьi am on the patreon and donated . i cant thank you enough. please carry on taking video in c++ :)😀 keep up the good work
Ответитьlegendary
Ответитьyou are a LEGEND legend
Ответитьme watching the last videos: mhm, mhm, yeah kinda makes sense, yup, i get that.
me watching this video: fuck it i'm going back to javascript.
int *myX;
const int * const getX() const{return myX;}
1 - return (pointer cant be modified)
2 – contents of pointer cannot be modified
3 – getX not modify actual class
Before video:🙄🤕
During video:🤔🤯🥰
After video:🧐
const++
Ответить