Operator Overloading Introduction | C++ Tutorial

Sdílet
Vložit
  • čas přidán 25. 02. 2022
  • How to use operator overloading in C++ to redefine how different standard operators work with different types of objects. Source code: github.com/portfoliocourses/c.... Check out www.portfoliocourses.com to build a portfolio that will impress employers!
  • Jak na to + styl

Komentáře • 14

  • @nabir14
    @nabir14 Před 29 dny

    I was stuck writting a program as i was confused about operator overloading but your video fixed my problem and I fully understood operator overloading.
    THANK YOU SO MUCH!

  • @nullifier_
    @nullifier_ Před 2 měsíci +3

    so in short: operator overloading is really telling a class how their objects should behave when they are put along into operations.

  • @benvingarten3674
    @benvingarten3674 Před rokem

    Hey, great video, what would happen if you would write: Number c = 4 + a;
    now the "this" object is 4 and not an instance of the Number class. how would you write the operator + then?

    • @cheeseboi9740
      @cheeseboi9740 Před 5 měsíci +1

      You would recieve an error, because the parameter is defined as an instance of the Number class, and if you wanted it to work like that you would need to define another overload.

  • @lradhakrishnarao902
    @lradhakrishnarao902 Před rokem +2

    Why did you use const keyword in the overloaded operator?

    • @PortfolioCourses
      @PortfolioCourses  Před rokem +2

      Great question! :-) It's 'const' because we're not going to change the "operand". We return a new number in the case of + and a bool in the case of ==, but in either case, we will not change the operand so we make it const.

    • @sabaresand7309
      @sabaresand7309 Před 7 měsíci +1

      @@PortfolioCourses Thanks for this clarification, because I thought 'const' was a mandatory one

  • @batebo2047
    @batebo2047 Před 21 dnem

    Love you

  • @mongraal2272
    @mongraal2272 Před 2 lety

    Sir can u plz do a video how Read an array of structs in C from a file

    • @PortfolioCourses
      @PortfolioCourses  Před 2 lety

      I agree this is a good idea, it's on my 'todo list', one day I will make a video like this. :-)

    • @PortfolioCourses
      @PortfolioCourses  Před 2 lety

      Here's a video I just made on reading and writing an array of structs from a binary file: czcams.com/video/0SkdAoVzWpk/video.html. One day I will make a vide on reading and writing an array of structs from a text file too.

    • @mongraal2272
      @mongraal2272 Před 2 lety

      @@PortfolioCourses thaaaaaks!!!

    • @PortfolioCourses
      @PortfolioCourses  Před 2 lety

      @@mongraal2272 you're welcome!

  • @OmidKazemini-pg5ix
    @OmidKazemini-pg5ix Před 9 měsíci

    Can you tutor me? :)