OPERATORS and OPERATOR OVERLOADING in C++

  Рет қаралды 367,878

The Cherno

The Cherno

Күн бұрын

Patreon ► / thecherno
Twitter ► / thecherno
Instagram ► / thecherno
Discord ► / discord
Operators Reference ► en.cppreference.com/w/cpp/lang...
Series Playlist ► • C++
Gear I use:
-----------------
BEST laptop for programming! ► geni.us/pakTES
My FAVOURITE keyboard for programming! ► geni.us/zNhB
FAVOURITE monitors for programming! ► geni.us/Ig6KBq
MAIN Camera ► geni.us/t6xyDRO
MAIN Lens ► geni.us/xGoDWT
Second Camera ► geni.us/CYUQ
Microphone ► geni.us/wqO6g7K

Пікірлер: 407
@sankalpsharma1755
@sankalpsharma1755 2 жыл бұрын
This guy is legit, for some reason after using C++ for 4 years, i feel like i never learned the language enough
@Tuho420
@Tuho420 Жыл бұрын
@@GH-jl2td this serie is more for beginners
@amosreginaldjr.4200
@amosreginaldjr.4200 Жыл бұрын
I’ve heard stories of people that’s been using c++ for 25+ years and they say it’s impossible to know everything. You learn it as you need it
@Tuho420
@Tuho420 Жыл бұрын
@@amosreginaldjr.4200 yeah c++ is closely impossible to "master"
@BlueDippy
@BlueDippy Жыл бұрын
@@Tuho420 chill😭
@Tuho420
@Tuho420 Жыл бұрын
@@BlueDippy why
@jerfersonmatos28
@jerfersonmatos28 4 жыл бұрын
After pausing the video 3 times, and meditating I finally got it, thank you Cherno
@lucasmorais3694
@lucasmorais3694 3 жыл бұрын
Ih ala, camisa do framengo brabo
@debjitmondal5281
@debjitmondal5281 2 жыл бұрын
soo true lol
@jerfersonmatos28
@jerfersonmatos28 2 жыл бұрын
@@lucasmorais3694 kkk, nois é hardcore
@lucasmorais3694
@lucasmorais3694 2 жыл бұрын
@@jerfersonmatos28 cara esperou dar 1 ano pra responder LOL
@jerfersonmatos28
@jerfersonmatos28 2 жыл бұрын
@@lucasmorais3694 é que eu nao tinha visto, mas de qualquer forma desde essa épouca que eu nao pratiquei mais programação kk, lembro mais de nada
@benjaminbirchman3732
@benjaminbirchman3732 2 жыл бұрын
Cherno, thanks for these videos. After taking a year off of coding after school to pursue something else, reviewing these topics from a real-world use-case standpoint makes them make a lot more sense as to what they are useful for compared to how we learned them in school. Yes, we learned them well in school, but it was rarely made clear as to what the expected usage of each topic should be. I now have a better understanding of when I should overload operators!
@eddyecko94
@eddyecko94 4 жыл бұрын
Love this channel, I wish I found it 5 years ago back in university
@justasydefix6251
@justasydefix6251 3 жыл бұрын
5 years ago, he wasnt even here doing c++ tutorials
@user-ic5nv8lj9d
@user-ic5nv8lj9d 2 жыл бұрын
@@justasydefix6251 lol
@puppergump4117
@puppergump4117 2 жыл бұрын
I found him 22 years ago when I was just starting
@mattgraves3709
@mattgraves3709 3 жыл бұрын
Boy thanks again. This series has been on loop in my home for 3 months. I have been needing to override the ostream and was wondering what to do... and == TY for showing those useful tips
@nakon7niket
@nakon7niket 2 жыл бұрын
Sometimes. you just go through so much information and you understand it but you don't really understand it. Then sometimes, you stop to think and apply what you just learnt and you really understand the concept and you feel like your brain just expanded a little. This is happening too frequently since I have started watching this series.
@codysing8291
@codysing8291 7 жыл бұрын
Just what i was interested in. Thanks for the great stuff
@hugoalmeida1291
@hugoalmeida1291 Жыл бұрын
This series is FABULOUS Cherno! You've clarified all of my doubts, thank u buddy =D
@antoinefortin1386
@antoinefortin1386 5 жыл бұрын
So clear, so neat and so well explained.
@jmg_1615
@jmg_1615 5 жыл бұрын
Thank you! I had difficulties with this but you made it a lot clearer.
@cortisol_induced_coma
@cortisol_induced_coma 2 жыл бұрын
Learning this in my CS class kinda made me die inside. I was able to understand you much more easily, thank you!
@benjamin_boeri
@benjamin_boeri 4 жыл бұрын
I'm loving C++ and your series
@shayaxelrod7691
@shayaxelrod7691 3 жыл бұрын
Dude.. Don't know why I read: "I'm loving c++ and your SISTER
@puppergump4117
@puppergump4117 2 жыл бұрын
@@shayaxelrod7691 My sister is already taken by me
@shayaxelrod7691
@shayaxelrod7691 2 жыл бұрын
@@puppergump4117 k
@xonxt
@xonxt 5 жыл бұрын
Basically do a: Vector2& operator++() { return (*this)--; } Vector2& operator--() { return (*this)++; } And watch the world burn. Pity that it wouldn't work.
@benjamin_boeri
@benjamin_boeri 4 жыл бұрын
You're evil, man
@nazeekk3873
@nazeekk3873 3 жыл бұрын
Or do: #define ++ --
@mrpedrobraga
@mrpedrobraga 3 жыл бұрын
@@nazeekk3873 mmmm my favourite language, C--
@kenan2386
@kenan2386 3 жыл бұрын
@Pedro Braga and mine C**
@Glomly
@Glomly 2 жыл бұрын
@@nazeekk3873 well your example will replace all ++ with -- . But in example above it will just call an infinite loop. IF any of it worked :)
@LS-to6qv
@LS-to6qv 9 ай бұрын
Taking my first programming class and this series has been really helpful. Thank you.
@Day13May
@Day13May 5 жыл бұрын
This is so much more clear now! thanks!
@pypunk6248
@pypunk6248 5 жыл бұрын
i got stuck with an assignment for school, also using a Vector2f class in c++, this video got me started :D thx, i appreciate the help
@insomicraiddict
@insomicraiddict 4 жыл бұрын
That was some fast talking.
@rajshekhar2953
@rajshekhar2953 4 жыл бұрын
not that fast I still have to download and watch it on 3x seed
@yasmin9718
@yasmin9718 4 жыл бұрын
@@rajshekhar2953 ok
@gengar807
@gengar807 3 жыл бұрын
@@rajshekhar2953 Weird flex but okay
@erwinschrodinger2320
@erwinschrodinger2320 3 жыл бұрын
I enjoy it being fast. I hate it when tutorials/guides go super slow.
@aligohar1708
@aligohar1708 3 жыл бұрын
😂 you can't even get a playback on 3x seed.
@Mandeepsingh-jo5cf
@Mandeepsingh-jo5cf 3 жыл бұрын
master class on operator overloading . Note: playback speed: 0.75;
@princessntomo6008
@princessntomo6008 2 жыл бұрын
thanksss🤧😂😅
@lisandrob626
@lisandrob626 4 жыл бұрын
man, I must seem crazy being alone and clapping after each amazing video, TXS
@RussTeeTrombone
@RussTeeTrombone 6 жыл бұрын
Bloody great video
@TW19567
@TW19567 Жыл бұрын
Wonderful explanation! Truly truly wonderful explanation of a pretty tricky concept to get your head around initially. Now it all makes sense.
@rudrOwO
@rudrOwO 4 жыл бұрын
How do I customize the debug console Visual Studio 2019 ?
@adamsperry2248
@adamsperry2248 6 жыл бұрын
Is the purpose of returning stream in the
@janusztarczykowski9003
@janusztarczykowski9003 5 жыл бұрын
Yeah, that's the reason, chaining is a really useful thing, especially you are going into functional programming
@floppy-disko2378
@floppy-disko2378 3 жыл бұрын
Thanks your question/answer cleared my dubt.
@kenan2386
@kenan2386 3 жыл бұрын
Me and the bois watching The Cherno and growing brain cells
@lolxdroflmao431
@lolxdroflmao431 3 жыл бұрын
By far my hardest C++ lesson, might have to review previous lessons
@lmnefg121
@lmnefg121 4 жыл бұрын
just love your lectures~!
@iamjovani
@iamjovani 7 жыл бұрын
Can the "
@MCLeo38638
@MCLeo38638 7 жыл бұрын
8:15
@aarushiagarwal8938
@aarushiagarwal8938 Жыл бұрын
It was really an informative video.Thanks Cherno😀
@nathanielsicard
@nathanielsicard 5 жыл бұрын
can you create custom operators? for instance if i wanted to make a class that represented a polynomial function and i wanted a member function that took its derivative would I be able to make say d an operator or would I have to either use a preexisting operator (making it harder to read) or be stuck with just the function?
@jingyaoyu2173
@jingyaoyu2173 4 жыл бұрын
well done! I finally understand!
@eman5300
@eman5300 3 жыл бұрын
Cherno My bro your one of the best teachers I've had and I didn't even pay you shit ! love your stuff man !!!
@rcookie5128
@rcookie5128 7 жыл бұрын
that's really cool!
@tomitomi7941
@tomitomi7941 Жыл бұрын
Man, you are amazing, thank you a lot for your videos.
@elhdllo9747
@elhdllo9747 4 жыл бұрын
Thank you that's exactly what I need. our instructor is just telling us non senses in school
@elhbailodiallo2629
@elhbailodiallo2629 4 жыл бұрын
Shivam Panwar ok lets assume that I don’t know how to write an operator overloading, I just don’t see in anyway you business in that? Please can you mind your business ignorant!
@Ethorbit
@Ethorbit 4 жыл бұрын
@@VideoHow And I'm pretty sure you can't structure a sentence properly because you're illiterate.
@marce3893
@marce3893 4 жыл бұрын
At 5:57 (and later at 11:09), is it okay to have a method call another one instead of doing the job itself in terms of performance? Is the assembly code exactly the same or?
@TheMR-777
@TheMR-777 4 жыл бұрын
Yes, your point is valid, I'm thinking the same. It'll be better Performance-wise. But to increase the functionality, and flexibility of the class, he did that. It's not always recommended. - If you're making a program for yourself, then do what you said. - If you're designing a Library, then do what Cherno did. It all depends.
@marce3893
@marce3893 4 жыл бұрын
@@TheMR-777 yeah I would never do that. but I was wondering if the compiler is smart enough to automatically optimize the code by "reducing" two (almost) immediate context switches directly into one
@TheMR-777
@TheMR-777 4 жыл бұрын
@@marce3893 If you are using the *Release Mode* , then most probably it would do that (what you are saying). Because, in *Release Mode* , Compiler always finds the best way (I mean, the shortest way) possible to optimize your code, in terms of Memory, and Code length. Your point is valid, Yes it's possible.
@Vladislav0Art
@Vladislav0Art 4 жыл бұрын
Nice vidoes, probably best on youtube! I have a question: can i write my own oparetors, for example, operator === instead of overloading native == ?
@damnstupidoldidiot8776
@damnstupidoldidiot8776 4 жыл бұрын
Not like that. However, you can make user defined literals which are like suffix operator unsigned long long operator""_sqr(const unsigned long long&x) { return x*x; }
@resignurdrnk7535
@resignurdrnk7535 4 жыл бұрын
thank you for sharing your knowledge
@maxpricefield7586
@maxpricefield7586 5 жыл бұрын
i'm working on a matrix library that works off of contiguous memory, so the basic way of accessing an element is Matrix[ columns*i + j ]; how can I implement operator overloading of [] such that I can still access it like Matrix[ i ][ j ]?
@danielconde001
@danielconde001 6 жыл бұрын
how bout operator[] ? not sure how that works
@huongpham3580
@huongpham3580 3 жыл бұрын
you literally saved my life!
@TheMR-777
@TheMR-777 4 жыл бұрын
At [ 5:57 ] you may have noticed he used the *operator* along with the *function* for the addition (which is defined just above that code by the way). Many of you may have thought ... Hey, can it cause performance issues !? , or can lead to slightly lower performance, the answer is ... *Yes* , but it depends ... - If you're making a *specific program* (for yourself), then do make a *single operator* , not along with the function.. As, it is really unnecessary. - If you're designing your own *specific Library* , then do what *Cherno* did. It will increase the *Functionality* and the *Flexibility* of your Library class. _Long story short ... It all depends._
@yrds96
@yrds96 2 жыл бұрын
What kind of performance can this leads? If a compiler sees a function using const parameter it will probably optimize this inlining function which will not call a function creating another stack to the program(unless you compile with debugging flags of course).
@TheMR-777
@TheMR-777 2 жыл бұрын
@@yrds96 Yes I agree, but there are cases, when you have a long and complicated library to make things more abstracted (i.e. ranges-v3, or fmt), and user is heavily dependent on it. In such cases, not all compilers are able to optimize, and inline everything as we expect (I have actually seen the differences, in C++ Weekly logs). And I agree with your point as well, it really doesn't matter, if we have a simpler class. But for long and complicated ones, just imagine that not everything can be optimized, and you are still responsible for many things. :)
@Reydriel
@Reydriel 2 жыл бұрын
@@TheMR-777 Isn't there a way to make sure the compiler inlines the function?
@TheMR-777
@TheMR-777 2 жыл бұрын
@@Reydriel Actually, it depends on the Compiler's Vendor, but still, there are some universal cases, where functions are inlined for sure. Like; - Calling any Function only once - Member Function, used only once - Calling the Function, having a few lines of code (roughly 3, or a little more), and called 2-3 times (or a little more). - Function with just a return statement (highly inlinable) But, sadly, there's no way to find explicitly whether the function will be inlined by the compiler. But if you meet any of the above cases, the compiler will optimize and inline your code for sure. Well, Compilers are quite trustable if you ask :)
@Reydriel
@Reydriel 2 жыл бұрын
@@TheMR-777 Looked it up, apparently you can set a flag in GCC to force inlining wherever the "inline" keyword is used, but it's not the standard behaviour
@huiyen2976
@huiyen2976 Жыл бұрын
Hey, Cherno, I really enjoy your video. I try to practice your technique. However, " return *this + other; " not work for me. I compile it with gnu g++. Is there any thing I missed?
@hanyuzhang4636
@hanyuzhang4636 2 жыл бұрын
For equal operator, do we need to define an errorThreshold epislon and compare two Vector difference with that epislon? Otherwise, the comparison result may be inaccurate.
@joshvictor110
@joshvictor110 5 жыл бұрын
I love how he gets tired of all the card thing lul
@anamnesis1992
@anamnesis1992 6 жыл бұрын
Is it possible to overload
@bamberghh1691
@bamberghh1691 5 жыл бұрын
9:47
@janusztarczykowski9003
@janusztarczykowski9003 5 жыл бұрын
It's not, since the left side is std::ostream, so you would need to add this overload inside std::ostream class, not inside Vector class.
@codinggod6244
@codinggod6244 4 жыл бұрын
You can make std::ostream as friend and define it basically in your class but your code can look messy rather just prototype it and define it outside of your class
@mrboyban
@mrboyban 3 жыл бұрын
Cherno deserves a medal!
@omarshahin4881
@omarshahin4881 4 жыл бұрын
I implemented leftshift operator as I said but gave an error like "ISO C++ forbids declaration of 'stream' with no type". What should I do instead?
@TheSexGod
@TheSexGod 4 жыл бұрын
At 7:32 will line 40 know to multiply first and then add? Does overriding the + and * symbol keep the order of operations?
@roozbehvalavi8700
@roozbehvalavi8700 Ай бұрын
Never fails to amaze me!
@MasterDigitalinfo
@MasterDigitalinfo 6 жыл бұрын
I am trying to make an operator oveload to insert the class atributes into a std::vector; but im really lost can someone send me on the right path?
@pxolqopt3597
@pxolqopt3597 4 жыл бұрын
did you solve it yet
@deleater
@deleater 4 жыл бұрын
Are your eyes really that color, it's cool man !
@HickoryJ
@HickoryJ 4 жыл бұрын
Do operator precedence rules remain the same upon being overridden, unless stated otherwise?
@ultimatedragon4281
@ultimatedragon4281 2 жыл бұрын
Considering that the precedence of * being executed before + was obeyed on the video (and on my computer with almost identical code), I would say "Yes".
@GfastGao
@GfastGao 5 жыл бұрын
Just jump back to say thank you & clicked the thumbs up button for this video. Is there anyone like me have the same feeling: See your tutorial save me to click "x1.5" or "x2" botton.
@SeanForeman
@SeanForeman 4 жыл бұрын
"I left out operator overloading (in java) as a fairly personal choice because I had seen too many people abuse it in C++. " James Gosling
@SeanForeman
@SeanForeman 4 жыл бұрын
@Peterolen I was just quoting Gosling (creator of Java) on why java doesn't have it... which is a dumb reason. I think we agree.
@ultimatedragon4281
@ultimatedragon4281 2 жыл бұрын
It is kinda like why Python doesn't have an easy, intended way to break out of a nested loops. The intended way is (if memory serves right) to write an if and break (or continue if you just want to skip that iteration) on EVERY SINGLE LEVEL NESTED LEVEL OF LOOPS. (rolling my eyes so hard I almost can look directly into my brain)
@harshalrathi8332
@harshalrathi8332 2 жыл бұрын
Hey Cherno, at 9:17 , why did we say that stream
@jituderaps9794
@jituderaps9794 2 жыл бұрын
that's a facilities of an istream library, basically everthing is stored as a sequence of character, so here we store it in stream called "stream" and then we return the stream. Think something like std::cin, std::cin is an object of type istream.
@harleendiaries
@harleendiaries 2 жыл бұрын
I had to pause the video in the middle to like and subscribe because it's worth it.
@antoniothomacelli
@antoniothomacelli 5 ай бұрын
Thank you for share!
@ncstarr2716
@ncstarr2716 4 жыл бұрын
your channels the best c++ tutorials on you tube without a doubt but man c++ is soooo much harder than python or php my brain is literally frying listening to you
@jacobcline6892
@jacobcline6892 4 жыл бұрын
So the operator overloads only apply to things done with Vector2 but nothing else? And what's this "other" thing he keeps passing? I don't see any passing going on but his functions have parameters. Does thing1 become the "other" that is passed in something like: thing1 + thing2 ?
@techwithjordan
@techwithjordan 3 жыл бұрын
I wish my brain would move as fast as you type
@joereinold6495
@joereinold6495 2 жыл бұрын
Can you ID an IDE that would highlight overloaded operators, such as color coding. It does make easier to read the code.
@anrkarpov3763
@anrkarpov3763 3 жыл бұрын
Why the output stream operator overloading function must be declared outside the struct scope ? why couldn't we declare it inside the struct ?
@slaincow4032
@slaincow4032 7 жыл бұрын
After the end of this series and the covering C++, can we get tutorials on a framework such as SDL or OpenGL? Or maybe something insanely new like Vulkan
@DridriLaBastos
@DridriLaBastos 6 жыл бұрын
With C++ you may prefer SFML rather than SDL
@shockminerx1518
@shockminerx1518 4 жыл бұрын
@@DridriLaBastos why?
@nishatmunshi4672
@nishatmunshi4672 Жыл бұрын
very informative thank you a lot
@Thadnill
@Thadnill Жыл бұрын
I have to ask, what is the meaning when you write " :x(x), y(y) {} before the body of a function? is it a faster way to declare the variables?
@node1738
@node1738 Жыл бұрын
It’s his way of writing a class constructor, it basically takes parameters on creation and sets x and y to their values
@matthewbrian6191
@matthewbrian6191 3 жыл бұрын
I just did the calculation on the PowerUp Vector and the Speed Vector, and it turns out that PowerUp is actually slower!
@landryplacid4065
@landryplacid4065 3 жыл бұрын
working on a g++, c++11
@Kumodatsu
@Kumodatsu 7 жыл бұрын
Say I'd wanted to implement an operation like vector/scalar multiplication, e.g. Vec2 v(2.0f, 2.0f); float s = 2.0f; Vec2 result = v * s; Since this is a commutative operation I'd like to also be able to define a result for s * v, with the float coming before the Vec2. This can't be done inside the class definition because it will just assume the left side of the operator to be the object itself. I know the operator for the other order can just be defined outside of the class, like: struct Vec2 { float x, y; Vec2(float x, float y); Vec2 operator*(float s) const; }; Vec2 operator*(float s, const Vec2& v); but this seems a bit messy. Are there any conventions/other solutions for this? Also, sorry for the wall of text ^~^
@damnstupidoldidiot8776
@damnstupidoldidiot8776 4 жыл бұрын
Pretty sure that's the only way to do it, it's only one line inside the function.
@Kumodatsu
@Kumodatsu 4 жыл бұрын
Yah, that is correct. To be honest I really don't remember what my issue with it was back then xD
@vertigo6982
@vertigo6982 6 жыл бұрын
06:43 He made the 'this' video, but didnt get to adding the link/card yet found here: kzfaq.info/get/bejne/kMWYg62Qqs7HlX0.html
@michaelswahla4927
@michaelswahla4927 2 жыл бұрын
If it helps from a python view, think of these operator overloading methods as deprecated methods from python (such as def __str__ and def __add__).
@talshinin1081
@talshinin1081 4 жыл бұрын
Can someone please explain why in the return you can write: return Vector2(.....); and not: return new Vector2(...); isn't the Vector2, that's created in the function gets destructed immediately? THANKS!
@joshuapaige8623
@joshuapaige8623 4 жыл бұрын
yes and no... when you return Vector2(...) you are essentially returning a copy of that. The Vector2(...) created in the function is destroyed at the end of the function, however, that doesn't matter because the function is returning a copy of that . The destruction of what you created has no effect on the returned copy of the object. new Vector2(...) would create an object on the heap and return a pointer to it so the return type of the function would have to be Vector2*.
@lucasmorais3694
@lucasmorais3694 3 жыл бұрын
The best part is Cherno is criticizing the Boost.Serialization Library xD
@9y070
@9y070 7 жыл бұрын
if you don't overwrite the equals method in java, it will do == and basically check if the are stored at the same memory location. is that the same in c++ when you don't overwrite the == operator, or won't it even work because you have to overwrite the operator ?
@platin2148
@platin2148 7 жыл бұрын
9Y0 It checks the value that is stored(only for int,char,long,short,float,double) only on pointers the addresses matter. Not guilty for classes. For them you don’t get any default operator else than the copy. It will probably complain with Invalid operands to binary expression or something like that.
@9y070
@9y070 7 жыл бұрын
so if I'm correct, you can't compile the following code without overloading the == operator: class Entity { private: int x; int y; }; Entity a; Entity b: std::cout
@Hopsonn
@Hopsonn 7 жыл бұрын
Exactly, you would need to overload the == operator for that.
@9y070
@9y070 7 жыл бұрын
thnx for making it clear. love your vids btw hopson
@Hopsonn
@Hopsonn 7 жыл бұрын
You're welcome and thanks :)
@freddy7304
@freddy7304 4 жыл бұрын
very challenging stuff to understand. wow.
@avi12
@avi12 4 жыл бұрын
0:36 Actually,
@mlecz
@mlecz 4 жыл бұрын
The operator's core of ' stream extraction / extraction operator). In the case of this video, the MAIN context is overloading the operators and their generalized implementation , not strict talking about IOSTREAM. Consequently, the notion used by Cherno is as correct as possible. Remember that IOSTREAM is just a library that you can include or not. Operators are in a different league. It's like class, namespace, int, float, template base etc. This is one of the foundations of language, with which things like IOSTREAM are built.
@jeejee4280
@jeejee4280 3 жыл бұрын
Actually Actually > is the extraction operator which works with std::cin.
@mlecz
@mlecz 3 жыл бұрын
@@jeejee4280 Yes, if we talk in context of IOSTREAM, then we call > as the extraction operator.
@letranminhkhoa7492
@letranminhkhoa7492 3 жыл бұрын
some powerful stuff, really.
@zch7491
@zch7491 4 жыл бұрын
lol @ the boost reference
@calebbarnes5452
@calebbarnes5452 4 жыл бұрын
So sick.
@Destrio_Fury
@Destrio_Fury 2 жыл бұрын
"What are you doing" *stares hard* LOL😆
@lyons1652
@lyons1652 3 жыл бұрын
tysm very useful
@sing759
@sing759 4 жыл бұрын
//I write outside Vector2 like below without overloading the operator
@yasenbonev7879
@yasenbonev7879 4 жыл бұрын
Well, as all things, it depends on what you're trying to do. In your case you are "gluing" yourself to the std::cout object. If you're overloading operator
@pxolqopt3597
@pxolqopt3597 4 жыл бұрын
why did you put // in your youtube comment?
@kaninchengaming-inactive-6529
@kaninchengaming-inactive-6529 3 жыл бұрын
@@pxolqopt3597 //Why not?
@starrio713
@starrio713 3 жыл бұрын
I got so confused when I saw std::string. 🤣 This vid really saved me! Thx for the content!
@patrickmayer9218
@patrickmayer9218 Жыл бұрын
If people need to go to the definition of your operator to understand what it does, you're probably not doing your job. Great video, Cherno!
@lijacky160
@lijacky160 2 жыл бұрын
Love u!
@pitter6282
@pitter6282 3 жыл бұрын
this video isnt for beginners.
@denxx56
@denxx56 3 ай бұрын
I don't see where it says it is
@paridhisingh2905
@paridhisingh2905 3 жыл бұрын
Why do we need to create an overload for
@shayaxelrod7691
@shayaxelrod7691 3 жыл бұрын
If you're creating your own class, c++ doesn't know how to print that class. So you have to tell it how.
@gabrielbraz9669
@gabrielbraz9669 Жыл бұрын
11:00 I believe the compiler is able to auto generate the operator!= if you opverload the operator==, so you don't need to define your own, since the compiler just will negate the other operator you have defined.
@user-qx7zu7xg6u
@user-qx7zu7xg6u Жыл бұрын
I tried. My compiler will say "error: no match for 'operator!='"
@alfen_
@alfen_ 5 жыл бұрын
What software is this???
@comfypillow2131
@comfypillow2131 5 жыл бұрын
Visual studio 2017
@abhisheksahoo7446
@abhisheksahoo7446 3 жыл бұрын
Nice one, Your T-shirt , that painting in the wall , your eyes all have the same hue of green Is it coincident or planned :P
@abhisheksahoo7446
@abhisheksahoo7446 3 жыл бұрын
Looks planned
@Katniss218
@Katniss218 4 жыл бұрын
Wouldn't having operator!=(...) return x != other.x || y != other.y be more efficient (since you don't have to check 'y' if 'x' already failed the comparison).
@DrGreenGiant
@DrGreenGiant 4 жыл бұрын
You missed the bool operator :)
@saladgaming7146
@saladgaming7146 4 жыл бұрын
No he didnt
@kiyasuihito
@kiyasuihito 11 ай бұрын
I'd be interested in a video about move assignment, copy assignment, assign by reference operators.
@muhammadtaimourafzal5285
@muhammadtaimourafzal5285 3 жыл бұрын
blows my mind
@oh4106
@oh4106 5 ай бұрын
How do u not make this into a recursive overload at 09:10?
@mojojojo890
@mojojojo890 3 жыл бұрын
Can we do overloading on member functions for classes that contain more than one variable ?? if so is the case then what should the operator compare and how .
@kenan2386
@kenan2386 3 жыл бұрын
I haven't understood this for a year, and this guy explains it in 7 minutes *_wow_*
@puppergump4117
@puppergump4117 2 жыл бұрын
Well it's not that complicated. You musta had some shoddy teachers.
@Chevifier
@Chevifier Жыл бұрын
3:40 could someone explain why he wrote the constructor lines 8 and 9 like that and not like Vector2(float x, float y){ x(x); y(y); }
@TonyDaExpert
@TonyDaExpert 3 жыл бұрын
Binge watching these before my data structure c++ based class in Uni
@andrewholden5900
@andrewholden5900 2 ай бұрын
following what you said about having operators be relevant, I have a really tough one. In electronics, the parallel impedance of some components is calculated by taking the inverse of the sum of the inverse impedances... like 1 / ((1 / z1) + (1 / z2)). In electrical engineering, it is commonplace to express this function with the || operator. do you think I would be out of line to overload that functionality into that operator?
@Erebus2075
@Erebus2075 5 жыл бұрын
awesome
The "this" keyword in C++
6:08
The Cherno
Рет қаралды 249 М.
lvalues and rvalues in C++
14:13
The Cherno
Рет қаралды 308 М.
НЫСАНА КОНЦЕРТ 2024
2:26:34
Нысана театры
Рет қаралды 1,4 МЛН
ОБЯЗАТЕЛЬНО СОВЕРШАЙТЕ ДОБРО!❤❤❤
00:45
小宇宙竟然尿裤子!#小丑#家庭#搞笑
00:26
家庭搞笑日记
Рет қаралды 12 МЛН
The purest coding style, where bugs are near impossible
10:25
Coderized
Рет қаралды 933 М.
Stack vs Heap Memory in C++
19:31
The Cherno
Рет қаралды 560 М.
WHY did this C++ code FAIL?
38:10
The Cherno
Рет қаралды 241 М.
10 Math Concepts for Programmers
9:32
Fireship
Рет қаралды 1,8 МЛН
CONST in C++
12:54
The Cherno
Рет қаралды 399 М.
SOME UNIQUE C++ CODE! // Pacman Clone Code Review
26:42
The Cherno
Рет қаралды 268 М.
My Brain after 569 Leetcode Problems
7:50
NeetCode
Рет қаралды 2,5 МЛН
C++ vs Rust: which is faster?
21:15
fasterthanlime
Рет қаралды 385 М.
НЫСАНА КОНЦЕРТ 2024
2:26:34
Нысана театры
Рет қаралды 1,4 МЛН