Never knew about this keyword. Thanks for the video.
@filipanjou22967 жыл бұрын
This comment would be funnier if it were posted on the video about the "this" keyword.
@princegupta67796 жыл бұрын
on seeing his comment i was gonna write almost what u wrote..but i saw ur then
@DerEinzigeNimmerland7 жыл бұрын
Cherno big shoutouts from germany, learning from you so much!
@christophmuller97284 жыл бұрын
Same
@PflanzenChirurg7 жыл бұрын
you actually getting alot People into coding c++
@rupeshmandke4 жыл бұрын
I had the exact same requirements for my toy ray Tracer where I had to count number of times particular ray had hit the object during traversal. I had to pass it as a modifiable function parameter or include it in common ray struct and then update .. wish I knew this couple of months back .. very handy for debugging.. thanks for sharing :-)
@princegupta67796 жыл бұрын
thanks for the concise explanation of all the topics...i really needed to get these topics covered thoroughly and quickly to start developing my JAVA and LWJGL game in C++ and openGL...THANKS A LOT
@aaQ-pv4wy Жыл бұрын
how is everything going?
@DavidRomigJr12 күн бұрын
Another use of mutable is to mark data as able to change outside the program, which stops compiler optimizations from caching the data- it will make it read from memory every time. You don’t really see this on typical modern computers, but you might on embedded systems and very old computers or maybe even in drivers- anywhere you have memory-mapped registers used for accessing hardware.
@shaikantest764626 күн бұрын
I'm surpised nobody talking about it, but besides the debugging and\\or gathering statistics another kinda canonical example of `mutable` application in classes is a caching of data. For example we may have a "getter" that makes a really heavy calculations to return the value - we don't want to make them every time getter is called, so we are caching the result of calculation for this particular object and only invalidate the cache, say, each 5 seconds.
@minecraftcookie2929 Жыл бұрын
for anyone watching this video after so long from being posted like me just a note that for const objects u have to explicitly declare a constructor or initialize each member variable but strings are exceptional std::string name dosent requires initialization !!
@serkanozturk42172 жыл бұрын
Personal Notes: -If you define an object as const in the main function, then to be abe to call a method on that function(obj.foo() ) , that foo() fuction must be const -Marking a class member as mutable means that const methods inside that class can actually modify that member
@MinhVu-dk3ym Жыл бұрын
tks for gut tips
@Yazan_Majdalawi Жыл бұрын
yep, and marking a member function as const means that it can be called on constant instances of that class. other member functions would cause an error.
@HrishikeshKulkarni7 жыл бұрын
I'm waiting for your heap and stack memory video. Please don't abandon it!
Vertigo wrong, watch cherno’s video. He allocated an array with size specified during runtime in stack
@gaymerjerry5 жыл бұрын
I always just say when teaching people programming early on "I'll explain in more detail later but in general stack is memory for functions heap is general memory"
@rauldragu94474 жыл бұрын
@@SteamX64 This might be a wee bit too late but in the hope of putting things straight i have to correct you. Vertigo is in fact right, you cannot allocate arrays on the stack of a size specified at run time. You may be able to do some weird stuff with the stack pointer but you shouldn't be doing that anyway. Also, i wasn't able to find anything like you described in his video about stack vs heap. I will present the proper way of achieving that in order to add some value to my reply. You can allocate an array like that on the heap like this : int* array = new int[n]; where n is any int (and you would have to delete it after you are done with it like this: delete[] array;). Doing it like this: int array[n]; won't compile, the compiler needs to know how much to advance the stack pointer at compile time and a variable's value can only be known at run time.
@eddieh79622 жыл бұрын
These are awesome for prepping cpp before a game dev job interview (at least for internship)
@johnbilodeau62964 жыл бұрын
Your explanations are interesting to watch. I use the mutable keyword only on mutex to allow the definition of const thread safe getter on active objects.
@TurtlesWithAutism4 жыл бұрын
Charno: randomly introducing a new concept while explaining a new concept 3:56 Me: Challenge accepted! >:)
@Hoptronics Жыл бұрын
@3:14 make me want to be able to give a special thumbs up for relevance.. like an ah ha moment
@h.hristov7 жыл бұрын
Thanks for these videos man.
@viraatchandra84986 жыл бұрын
Should we really be returning a reference of a stack created object (like in 1:45). What if we assign it to a value like: std::string a = entity.GetName(); and entity goes out of scope and is destroyed... what will happen to `a`?
@zdspider6778 Жыл бұрын
6:03 You actually did use "mutable" with a lambda. In the _"Reading/Writing C# Fields in Editor // Game Engine series"_ video from the other channel (Cherno Unplugged) at 1h21m52s. I can't link it because then my comment won't be visible to other viewers, but it's there.
@videogamesarecool928015 күн бұрын
damn, thats a deep cut
@rcookie51287 жыл бұрын
wow soooo many videos recently!!
@naveenvenugopal83344 жыл бұрын
@cherno. As you know, your presentation style is awesome and I am now watching your videos in 0.75 speed to fully understand the content LOL :)
@SrIgort5 жыл бұрын
Thanks I didn't know about it but it seems to defeat the whole propose of a const function lol
@sillfsxa19274 жыл бұрын
learning how to use matters, but learning where to use is more important. the way you teaches, is the first one... for the second one, you only say in some situations, there will be some cases that we need to use some remedies! that sucks
@EchoVids2u2 жыл бұрын
I am discovering so many things I had no idea you could do in C++
@tuds82 жыл бұрын
you’re a legend man!
@GenericPhantom1 Жыл бұрын
Lambda is a throwaway function Also mutable means changeable or something like that
@rohitkumarshrivastava96932 жыл бұрын
What is the difference between `const std::string& GetName() const` and `const std::string GetName() const`?
@deniz-gunay2 жыл бұрын
did you learn the difference? i did not understand why he used the ampersand here.
@rohitkumarshrivastava96932 жыл бұрын
@@deniz-gunay Still no. Waiting for him to see this comment and reply.
@gamescreator50406 ай бұрын
The & version returns a const reference to your member variable, while the version without & returns a copy of your string. This means that the member string will be copied and returned, so you can safely change the copy without affecting the member variable. In this case, you should omit const because it doesn't make much sense; therefore, it should be std::string GetName() const. you asked about this one year ago, so I guess you’ve figured it out by now...
@Hoptronics Жыл бұрын
After watching like 1/2 these videos im surprised by code back in the early 1990s and 2000s even worked.. i was on a team of 3 writing edi transactional banking applications for a private edi VAN.. also one of the first to implement authentication using an LDAP server before microsoft had its Active Directory Server stuff.. i guess it just goes to show there's more than 3 ways to skin a cat..
@surbhijain12815 жыл бұрын
Can you tell the difference between const and constexpr here? const int a =5; constexpr int a = 5;
@ChildOfWar1114 жыл бұрын
what is the meaning of the '&' in "const string& GetName()"????? its the same if you delete it !
@simosimo76004 жыл бұрын
you should see his video about references
@bhaskarjat61604 жыл бұрын
what string& exactly means is that you will be returning the actual reference of the string, the value of which if changed, will change the value of the actual variable which was returned from the function
@__hannibaalbarca__ Жыл бұрын
Yeah i see this key word in Bjarn books, but i never used (only one time).
@baaryl7 жыл бұрын
Maybe you could prepare an episode about lambda functions or smart pointers?
@mikicerise62502 жыл бұрын
C++: Code yourself into a knot. Code yourself out of the knot with additional code. 😜
@IMMORTALmen2 жыл бұрын
What about mutex in const methods? Should we mark a mutex as const for be able to lock/unlock it?
@RandellTrulson3 жыл бұрын
When you put a cactus next to your computer, then wave your hand around talking about stuff....LOL yeah.
@nazar17447 жыл бұрын
once again a nice video! Can you actually recommend a website to practice c++ coding? I've found some but they are not very beginner-friendly.
@xkcd9637 жыл бұрын
exercism
@ibiixie7 жыл бұрын
SoloLearn is great for beginners
@Gilpow6 жыл бұрын
The Shroom SoloLearn is not for practice coding
@surbhijain12815 жыл бұрын
Can we use final keyword like this? final int a =0;
@yosuamartiansia34445 жыл бұрын
Can anyone explain the use of const std::string&? I know the use of const after the method, but I csnt understand why he would put const before the return type
@DiegoBM4 жыл бұрын
@firehazard your reply should be added as part of Cherno's comment on the consts video sir
@giuliograziani32613 жыл бұрын
awesome mate
@avineshbenjamin1782 Жыл бұрын
const std::string& will result in the string copied right?
@christiancox973 Жыл бұрын
I think it will return a reference to the actual value in the object (not copied) but one that is const so you can't modify the value through that reference.
@justanotherguy55164 жыл бұрын
Can anyone explain if mutable can be used with const pointers?
@abhijeetjain047 жыл бұрын
Can you make video on lambda function !!
@TheKautschuKMedia4 жыл бұрын
seems like a terrible concept tbh having a const method is a contract which gets broken by mutable. the usage with lambas seems to be bug prone... reading the code one might assume x++ actually incremented x, but it didn't in the outside scope.
@mrbee83365 жыл бұрын
Thanks
@axeldaguerre88385 жыл бұрын
someone knows how he get this 'linter' when is is typping ? I have visual assist, enable the inspect feature but still never have underline error when i am typing something wrong. It could really help me during my leanring because my computer is quite slow at building so i waste time, and understanding of the language on how it really works
const std::string& GetName() const i know that 2. const prevent programmer to change member variable in class but what is 1. const mean. what things prevented when i type const in front of function?
@zdspider6778 Жыл бұрын
It makes it a const reference. You could even write it like: std::string *_const&_* GetName() const The compiler doesn't care. It's a stylistic choice called "East Const" (as opposed to "West Const"). If there wasn't "const" there, it would just be a reference. Because of the "&" symbol.
@ren69ade7 жыл бұрын
Please do a video on lambdas (auto) things, this is a first time I have seen this in c++, and I thought I actually knew quite a lot about c++. Apparently not. Good stuff man, keep up with a good work.
@ericrussell53047 жыл бұрын
i had been away from c++ for quite some time. I came back and saw all those autos and lambdas and stuff and it left my head spinning!
@pxolqopt35974 жыл бұрын
i guess c++ is one of those language that is impossible to truly master because of all the features it has
@sergeyklassen96967 жыл бұрын
Love the series! Keep up the great work!
@einsjannis Жыл бұрын
This is so cursed
@chadgregory9037 Жыл бұрын
brit accent > aussie accent?
@einsjannis Жыл бұрын
@@chadgregory9037 yes but what does that have to do with my comment, I was talking about mutability in C
@tsibulsky4900 Жыл бұрын
Thank you very much for your videos 👍👌🙏
@akr.28182 жыл бұрын
What is the keyboard method to do this 3:00?
@zdspider6778 Жыл бұрын
Hold Alt and press Arrow Up / Arrow Down.
@richardrisner9213 жыл бұрын
Whoa!
@vaishanthjv2519 Жыл бұрын
Why is std::string passed by reference?
@oshaynecastle92125 ай бұрын
if i ahve a felony how can i get a job in the coding world. especially if the situation is unbelievably circumstantial.
@aradhayaarora61553 жыл бұрын
why did you use a reference to string returning from GetName() method?
@max12313 жыл бұрын
It helps the performance, as it’s not copying the data on the heap (otherwise it would)
@deniz-gunay2 жыл бұрын
@@max1231 why heap? not stack?
@matthewsanetra7 жыл бұрын
What is the difference between a mutable and a mutex?
@AgentM1247 жыл бұрын
Mutex is a variable type that can be accessed by multiple threads. mutable is a type augment/modifier like const, to define it's accesibility. Not a true C++ god, but this is what I have understood.
@Trogzul7 жыл бұрын
I would say your half-right. You can access a mutex from multiple threads, but it is usually not the mutex itself you are interested in, rather the variables it protects. You can use a mutex to protect variables that can be accessed by multiple threads. Usually you will lock on the mutex, then access the data the mutex is protecting, then release the lock. Alternatively you could make the variable atomic (if this is feasible, depends on the situation). One example of where to use mutable variables is actually in relation to mutexes. Because if you have a mutable mutex in your class, you can use that to protect your data in const functions. You can see an example here: hastebin.com/eliteyapiz.cpp (Yes it would be better to use a lock_guard in the example).
@AgentM1247 жыл бұрын
Trogzul that sounds better. Thanks 😊
@lysdexic91297 жыл бұрын
when you first discuss Lambdas you pass by value and the compiler complains, if your are passing by value why is mutable required as you are passing a copy of the value?
@max12313 жыл бұрын
Because the compiler creates a copy that is const by default, so you have to tell it to not to make it const
@huaxingzheng62085 жыл бұрын
Thanks, I like it! I like you!
@b4ttlemast0r2 жыл бұрын
the lambda usage seems more confusing than useful
@svenbtb Жыл бұрын
You just have to learn where it's helpful, most C-like programming languages use it
@theamazedones31017 жыл бұрын
what is the use of auto keyword ?
@matthewsanetra7 жыл бұрын
at the time of compiling it will check what is the best variable type to place there. example: auto var = 1; // Would make the variable 'var' an 'int' auto var = { 5, 2, 3 } // Would the variable 'var' an 'int[]' Once you set an auto to an int (for example), you cant set it to a string (or any other type). Think of auto as 'var' in JavaScript, or C#
@Trogzul7 жыл бұрын
Just quick small thing, because it is easy to get that wrong, and can be hard to spot. Currently auto var = {5, 2, 3} will make std::initializer_list. There is no good way to create regular C arrays with auto unfortunately. The reason he uses auto here is because the type of lambda's are implementation defined, so you can't spell the type yourself.
@shushens3 жыл бұрын
The lambda example is not a different usage. A lambda is a const functor that can be invoked using parentheses operator. Since it is NOT a throw-away function and can be passed elsewhere, variables passed to it by value become a part of its state, which gets carried with it. Very bad idea to make it mutable. This should have been elaborated more.
@manai26832 жыл бұрын
I never use the mutable keyword because I never make my functions const... I know that's bad but I really don't see the use for it. Especially since other langauges like C# doesn't have it and they survive just fine.
@zdspider6778 Жыл бұрын
Yeah, until someone uses your function to do stupid crap like "GetSomeValue() = myOtherValue;" and assigns a value to it that you didn't intend, lol. This is C++. You should be sprinkling that shit _everywhere._ So many exploits were fixed in the Linux kernel by just adding 'const' to things. There's even an Indian girl who pretty much only contributed 'const' to it and got a scholarship because of those contributions.
@svenbtb Жыл бұрын
I mean, you could say the same thing about pointers. Just because they aren't in C# doesn't mean that they don't have value and they don't have their place. C++'s whole point is that it gives you more control to do what you want, but you just have to be careful and pay attention, so that you don';t shoot yourself in the foot (and also clearly document your code so that someone using your code doesn't shoot their foot). I'm currently learning C++ but have experience using C#, it definitely is an adjustment but you just have to learn how to think differently. If you don't like it then just stick with C#, simple.
@joseponce62503 жыл бұрын
cool!!
@chenjin64074 жыл бұрын
Anyone knows what the const in the return variable type (eg: const std::string& ) does?
@ipizza9941 Жыл бұрын
Figured it out yet? I would like to know.
@matt-g-recovers3 жыл бұрын
For those that don't know Lambdas are based on Lambda calculus so... Ya know,... Go take an advanced mathematics course to understand them :>)
@user-if1ey5sm1v3 жыл бұрын
I know this is a very, very late comment. But are their any downsides by using this?
@user-if1ey5sm1v3 жыл бұрын
@Peterolen thanks
@AntiWanted3 жыл бұрын
Nice
@AbdulMoiz-ho8rx2 жыл бұрын
nice
@bloodwolf83074 жыл бұрын
cool
@skyseed30052 жыл бұрын
tenk yuuuu
@szinton7 жыл бұрын
Could You please explain Lambdas little better? I get the idea after watching this video, but I have no idea where I would use it in code.
@platin21487 жыл бұрын
Szinton A good example std::sort std::remove_if but it is really only syntactic sugar.
@szinton7 жыл бұрын
K, thanks! =)
@timangar97713 жыл бұрын
Lambdas look pretty scary lol
@Nicolas-gq9vu7 жыл бұрын
Thanks for this nice video! (And please, make a video on lamdas)
@ryanzwe7 жыл бұрын
Why do people always use m_ ?
@TheCherno7 жыл бұрын
It's a convention to distinguish class members from local variables.
@southparkclips2213 жыл бұрын
One question here! Why do there's an ampersand on the Function?? "Const std::string& GetName() Const"
@masheroz3 жыл бұрын
That refers to a reference, rather than the value.
@austinfritzke93054 жыл бұрын
can be a bit verbose in your introductions
@sahilsingh14 жыл бұрын
It just seems absurd. You want an object /class method to be const, but then you want to make some class variable "mutable"? Isn't that a poorly written code in the first place?
@atahirince2 жыл бұрын
look like lambda is black magic in here, god bless us!
@heetgorakhiya22424 жыл бұрын
But, why not put the m_Debugcount variable in public?
@svenbtb Жыл бұрын
I know this is 3 years later, but if someone else with the same question happens across this, he's creating a hypothetical counter to see how many times that the function gets called, so he wants it to be associated with THAT class/instance. So, he would probably take this and within the class also have a getter or a print function that returns this value, so when testing you could see how many times the function was called. This would be useful for, say, testing that the function gets called the correct number of times when you're making a loop or a state-machine or something like that, and making sure that everything is going as expected.
@heetgorakhiya2242 Жыл бұрын
@@svenbtb I've moved to a completely different language, but thanks for taking the time to explain
@taukakao Жыл бұрын
This sounds absolutely horrible for readability. Good explenation tho.
@AmirSepasi6 жыл бұрын
what is the editor that you are using in your demonstrations? Thanx.
@drwisdom14 жыл бұрын
I feel like I just got kicked in the brain. All of this is unnecessary including mutable, lamba functions, and passing by reference.
@dimitar.bogdanov3 жыл бұрын
I don't know about the first two but passing by reference is not unnecessary.
@drwisdom13 жыл бұрын
@@dimitar.bogdanov Passing by reference is an alternative syntax to using pointers. I like pointers better and avoid passing by reference. The only time passing by reference is required is for things like copy constructors (which could have used pointers) and calling external code that uses passing by reference args. Passing by reference was created for programmers who like periods but are scared of "->".
@dimitar.bogdanov3 жыл бұрын
@@drwisdom1 Passing by reference is syntax sugar, yes. It's made to have your programs be a little more easier to digest. As a person who is coming from C# where you just have the ref keyword, passing by reference is much easier than having a pointer and rely on IntelliSense and the compiler to even be able to learn when to use a period or ->
@forhadrh3 жыл бұрын
hello guys my name is a Chennai welcome back to my say plus plus series - Close enough youtube! You are soo close... 😂
@Thesurvivour-yl3hd7 жыл бұрын
c++ lambda tutorial/overview? pls?
@Krokoklemmee7 жыл бұрын
he said that he'll be covering them in a later video. If you can't wait for that, you can check this out en.cppreference.com/w/cpp/language/lambda
@gavinw777 жыл бұрын
Great demo/explanation of mutable. Learning++; But once again, you go too fast. eg at 4:12 you haven't even written the semicolon at the end of the lambda body when you switch screens. You've gotta think of how people are following along, for instance, I've got VS open SBS punching in the samples to see it working. You're forcing me to be constantly pausing and rewinding to keep up. It's a 7 minute video, it wouldn't hurt to throw in an extra 30 seconds of moments. Is it so important that we see your face instead of an extra couple of seconds of looking at the code. You can keep talking.
@jeffzz1112 жыл бұрын
it is 9, not 8...
@svenbtb Жыл бұрын
Within the Lambda function, it would return 9, yes. outside the function it still returns 8.
@LKokos4 жыл бұрын
wtf is this color grading jesus
@anthonysteinerv3 жыл бұрын
why are C++ lambdas so fucking horrible to write...
@zdspider6778 Жыл бұрын
It's one of the shortest forms to express how a function should perform and behave. Sometimes you want them to reference everything by value, other times you want everything by reference (to be able to modify them), and other times only _one_ variable by reference and everything else by value. The shortest lambda is technically: [](){} 😆 And it compiles.
@kcvinu4 жыл бұрын
Sorry, but it's too fast for non-English people.
@chadgregory9037 Жыл бұрын
this is the video when shit starts feeling as messy as java... god fucking dammit lol
@svenbtb Жыл бұрын
Imo I still prefer this way more than Java lol. Learned a little Java and it's way too verbose and awkward to work with, this makes a lot more sense to me. Guess it just depends on your preference though.