Operator Overloading In C++

Поділитися
Вставка
  • Опубліковано 10 гру 2024

КОМЕНТАРІ • 78

  • @hsaidinsan6345
    @hsaidinsan6345 4 роки тому +15

    What makes me angry is this channel deserves more subscribers and viewers
    But this is c++, not all the folks like it 🤷‍♂️

    • @CppNuts
      @CppNuts  4 роки тому +8

      Its ok we will reach slowly 😊 thanks man!!

    • @haldharpatel3915
      @haldharpatel3915 3 роки тому +1

      I think so too.

  • @lil_hrushi
    @lil_hrushi 3 роки тому +4

    I was pissed at people just using the same complex number example. And after seeing this use, I was really happy. Thank you! :D

  • @yusufahmed2233
    @yusufahmed2233 6 років тому +2

    just saved me a lot of time, useless effort and a bunch of marks. Thanks man

    • @CppNuts
      @CppNuts  6 років тому

      You are welcome dude!!

  • @abrarulhaqshaik
    @abrarulhaqshaik 3 роки тому

    your channel is one-stop solution for c++

  • @suvamjha6217
    @suvamjha6217 4 роки тому

    Best tutorial on c++ on youTube, thank you.

    • @CppNuts
      @CppNuts  4 роки тому +1

      Glad you think so!

  • @TheGruselmops
    @TheGruselmops 5 років тому +4

    We all know it will print .. CURRY!! xD
    Thanks man great tutorials !

    • @CppNuts
      @CppNuts  5 років тому

      you are most welcome dude!!

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

    Best example to demonstrate operator overloading

  • @hydrocy.9165
    @hydrocy.9165 9 місяців тому

    6:35 how does complier identify that p1 calls "operator +" and the parameter (const point&rhs) is for p2?

  • @Ishan301
    @Ishan301 3 роки тому

    Nice content. This Channel deserves more subs and likes

    • @CppNuts
      @CppNuts  3 роки тому

      I appreciate that!

  • @akhiljain1695
    @akhiljain1695 4 роки тому +2

    Amazing and super simple explanation.

    • @CppNuts
      @CppNuts  4 роки тому

      Thanks you man!!

  • @ergingokkaya8323
    @ergingokkaya8323 5 років тому +3

    I have a question. I am sorry it may be a silly one. x and y are private in Point class. How can it be possible that rhs (an object of that class) accesses the private data members? Like rhs.x and rhs.y

    • @CppNuts
      @CppNuts  5 років тому +1

      private means you can not use out side of that class but if you are accessing in the class (in member function of same class) then it is allowed.

    • @ergingokkaya8323
      @ergingokkaya8323 5 років тому

      @@CppNuts this is the answer I already expected😅. But it still seems weird to me. Eventually, when I am working on the object p1, I access another object's private member. Anyway I need to accept this😊 thank you

  • @Brusselsprouts2023
    @Brusselsprouts2023 5 місяців тому

    best explanation for operator overloading.

  • @nehaa6212
    @nehaa6212 3 роки тому

    I think default constructor is missing here. For line number 19 (Point p;) there should be default constructor. Correct me if I am wrong.

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

    when it returns the point object then copy constructor is being called right?

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

    Sir which compiler you are using?

  • @haryan1627
    @haryan1627 6 років тому +3

    You are great man!
    thank you.

    • @CppNuts
      @CppNuts  6 років тому

      Thanks for the comment man!!

  • @alliswell6587
    @alliswell6587 5 років тому +1

    which IDE you are using to demonstrate????

    • @CppNuts
      @CppNuts  5 років тому

      Sublime text editor 3

  • @LightYagami-jq1yc
    @LightYagami-jq1yc Рік тому

    Great work sir, thank you so much!

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

    Line 17 how 7:52 how assigned x and y

  • @cid007007
    @cid007007 4 роки тому +1

    Can i add more than 2 objects or user-defined datatypes ?? If yes.. how ? any video or link or code ?

    • @CppNuts
      @CppNuts  4 роки тому +1

      Yes you can do that assume z = a + b + c;
      Now b and c will be added and one temporary object will get created and that temporary object will be added with a and result will be assigned to z.
      But sorry I don't have any video for this.

  • @HemaLatha-qj5co
    @HemaLatha-qj5co Місяць тому

    Why we need operator overloading if we want anything we can implement in the class only why we need to do object addition and multiplication
    In which scenario it will helpful
    This was asked in an interview

    • @CppNuts
      @CppNuts  Місяць тому

      Correct, but to keep mathematics equations look same these options are given.

  • @cid007007
    @cid007007 4 роки тому +1

    Can we add or subtract 2 different user defined datatypes ( I mean 2 different classes of same datatyppes or 1 structure and 1 class of same datatypes ???)

    • @CppNuts
      @CppNuts  4 роки тому

      Already answered in one of your previous questions.

  • @farikunaziz6504
    @farikunaziz6504 3 роки тому +1

    Point operator + (const Point &p){
    x += p.x;
    y += p.y;
    return *this;
    }
    same result~

  • @ALIAYH-r7p
    @ALIAYH-r7p 7 місяців тому

    Thank you doctor👌👌👌👌👌

  • @AlokKumar-zx4bm
    @AlokKumar-zx4bm 6 років тому +1

    how operator precedence is solved in case of operator overloading. Suppose we have + and * operator overloaded in our class/struct. How expression p1 + p2 * p3 is solved ? Kindly explain it further.

    • @CppNuts
      @CppNuts  6 років тому

      Consider using round bracket.

    • @AlokKumar-zx4bm
      @AlokKumar-zx4bm 6 років тому +1

      This is the simplest hack one could have to make code working.However, I want to learn how can I define operator precedence in class or struct. C++ compiler has grammar associated with it, which helps in solve this case of precedence and direction of associativity, but they are compile time concepts but operator evaluation is run time concept. How can we inherit or implement or define or solve such case here while we use operator overloading ??

    • @CppNuts
      @CppNuts  6 років тому +1

      As i thought it would be very hard to implement because you must be knowing every precedence inorder to apply it in overloading. And here is the link you may need to have more comments on this topic.
      softwareengineering.stackexchange.com/questions/161049/can-i-change-operator-precedence-and-associativity-in-c

    • @CppNuts
      @CppNuts  6 років тому

      Yes!! That's what that link is about!!

  • @mozeidan6481
    @mozeidan6481 3 роки тому

    Great explanation as usual!

  • @hemantgarg9339
    @hemantgarg9339 4 роки тому

    Hey your video is great,but i wanna know that aren't we accessing the private data of p2 with help of &rhs outside the class ,i.e. we are simply adding rhs data which is private for rhs i.e. reffering to p2 object.

  • @ranakhan7815
    @ranakhan7815 4 роки тому

    Hi,i tried to acess private variables outside the class in operator overload but i couldn't using friend function please guide me on this

  • @knowhereeverythingchannel2351
    @knowhereeverythingchannel2351 9 місяців тому

    loved it ❤❤❤❤❤❤❤❤

  • @anushreebachhav9299
    @anushreebachhav9299 3 роки тому

    hello sir, can ypu tell me, why have we initialised x and y=0, despite we have initialised it to other x and y?? and why does the compiler give error when they arent initialised to zero??? please help !!! and thanks:)

  • @baba-ti2gb
    @baba-ti2gb 6 років тому +2

    very nyc sir u are Awsm..

    • @CppNuts
      @CppNuts  6 років тому +1

      Thanks dude!!

  • @ramakrishnam5455
    @ramakrishnam5455 3 роки тому

    sir,here object p created in the function gets memory deallocated after function returns,as it's in function scope right? then how could the address returned by the functione be used by p3 in main!please clarify

    • @CppNuts
      @CppNuts  3 роки тому

      Please specify timing, with that i can directly open that video and tell the solutions, in future also please specify time.

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

    sir why we r using reference variable

  • @hope-jh7bv
    @hope-jh7bv 3 роки тому

    Thank you so much 🥰

    • @CppNuts
      @CppNuts  3 роки тому

      You’re welcome 😊

  • @indian_geocacher
    @indian_geocacher 3 роки тому

    Can anyone explain why const is used and also why refernece variable is used

    • @CppNuts
      @CppNuts  3 роки тому +1

      const : because we don't want to allow our objects to be modified.
      reference: because we don't want to pass object as value otherwise it will be unnecessary copy.

  • @imcnx1563
    @imcnx1563 4 роки тому

    Why const Point& rhs and not const Point rhs?

    • @CppNuts
      @CppNuts  4 роки тому

      It will make temporary copy of Point for no reason.

  • @trevorscott3275
    @trevorscott3275 4 роки тому +1

    I like your video

  • @akrammd13
    @akrammd13 5 років тому +1

    which compiler?😬

    • @CppNuts
      @CppNuts  5 років тому +1

      G++ compiler.

    • @akrammd13
      @akrammd13 5 років тому +1

      @@CppNuts Thanks Nuts!☺

  • @alakhniranjanofficial
    @alakhniranjanofficial 6 років тому +2

    simply great !!

    • @CppNuts
      @CppNuts  6 років тому

      Thanks Alakh bhai 😀

  • @twilight4177
    @twilight4177 Місяць тому

    god may bless you with long age i wish and pray for you

    • @CppNuts
      @CppNuts  Місяць тому

      Thanks!! Much Needed!!

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

    #include
    using namespace std;
    class space{
    public:
    int x;
    int y;
    int z;

    void getdata(int a,int b,int c)
    {
    x=a;
    y=b;
    z=c;
    }
    void display(){
    cout

    • @deepakjangra1974
      @deepakjangra1974 11 місяців тому

      The thing you are trying to do is putting -ve sign infornt of every data member in the class
      What you have to do is create another object S2,S3 and insert value in S3
      Now you just have to assign S3 = S1 - S2
      Also your operator - function is not correct
      Please refer below code for refference
      #include
      using namespace std;
      class space{
      public:
      int x;
      int y;
      int z;
      void getdata(int a,int b,int c)
      {
      x=a;
      y=b;
      z=c;
      }
      void display(){
      cout

  • @ALIAYH-r7p
    @ALIAYH-r7p 7 місяців тому

    👌👌👌👌👌