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 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
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.
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
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 ???)
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.
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 ??
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
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.
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:)
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
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.
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
What makes me angry is this channel deserves more subscribers and viewers
But this is c++, not all the folks like it 🤷♂️
Its ok we will reach slowly 😊 thanks man!!
I think so too.
I was pissed at people just using the same complex number example. And after seeing this use, I was really happy. Thank you! :D
just saved me a lot of time, useless effort and a bunch of marks. Thanks man
You are welcome dude!!
your channel is one-stop solution for c++
Thanks man..
Best tutorial on c++ on youTube, thank you.
Glad you think so!
We all know it will print .. CURRY!! xD
Thanks man great tutorials !
you are most welcome dude!!
Best example to demonstrate operator overloading
Thanks man.
6:35 how does complier identify that p1 calls "operator +" and the parameter (const point&rhs) is for p2?
Nice content. This Channel deserves more subs and likes
I appreciate that!
Amazing and super simple explanation.
Thanks you man!!
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
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.
@@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
best explanation for operator overloading.
Thanks!!
I think default constructor is missing here. For line number 19 (Point p;) there should be default constructor. Correct me if I am wrong.
when it returns the point object then copy constructor is being called right?
Sir which compiler you are using?
You are great man!
thank you.
Thanks for the comment man!!
which IDE you are using to demonstrate????
Sublime text editor 3
Great work sir, thank you so much!
Line 17 how 7:52 how assigned x and y
Can i add more than 2 objects or user-defined datatypes ?? If yes.. how ? any video or link or code ?
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.
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
Correct, but to keep mathematics equations look same these options are given.
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 ???)
Already answered in one of your previous questions.
Point operator + (const Point &p){
x += p.x;
y += p.y;
return *this;
}
same result~
Thank you doctor👌👌👌👌👌
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.
Consider using round bracket.
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 ??
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
Yes!! That's what that link is about!!
Great explanation as usual!
Thanks..
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.
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
loved it ❤❤❤❤❤❤❤❤
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:)
very nyc sir u are Awsm..
Thanks dude!!
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
Please specify timing, with that i can directly open that video and tell the solutions, in future also please specify time.
sir why we r using reference variable
Thank you so much 🥰
You’re welcome 😊
Can anyone explain why const is used and also why refernece variable is used
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.
Why const Point& rhs and not const Point rhs?
It will make temporary copy of Point for no reason.
I like your video
Thanks!!
which compiler?😬
G++ compiler.
@@CppNuts Thanks Nuts!☺
simply great !!
Thanks Alakh bhai 😀
god may bless you with long age i wish and pray for you
Thanks!! Much Needed!!
#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
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
👌👌👌👌👌
Thanks!!