Operator Overloading Introduction | C++ Tutorial

Поділитися
Вставка
  • Опубліковано 18 жов 2024
  • How to use operator overloading in C++ to redefine how different standard operators work with different types of objects. Source code: github.com/por.... Check out www.portfolioc... to build a portfolio that will impress employers!

КОМЕНТАРІ • 14

  • @nabir14
    @nabir14 4 місяці тому +2

    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_ 5 місяців тому +5

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

  • @lradhakrishnarao902
    @lradhakrishnarao902 2 роки тому +3

    Why did you use const keyword in the overloaded operator?

    • @PortfolioCourses
      @PortfolioCourses  2 роки тому +6

      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 10 місяців тому +1

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

  • @benvingarten3674
    @benvingarten3674 Рік тому

    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 8 місяців тому +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.

  • @batebo2047
    @batebo2047 3 місяці тому

    Love you

  • @mongraal2272
    @mongraal2272 2 роки тому

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

    • @PortfolioCourses
      @PortfolioCourses  2 роки тому

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

    • @PortfolioCourses
      @PortfolioCourses  2 роки тому

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

    • @mongraal2272
      @mongraal2272 2 роки тому

      @@PortfolioCourses thaaaaaks!!!

    • @PortfolioCourses
      @PortfolioCourses  2 роки тому

      @@mongraal2272 you're welcome!

  • @OmidKazemini-pg5ix
    @OmidKazemini-pg5ix Рік тому

    Can you tutor me? :)