how cin>>d; can call the overloaded operator >> as it is like a function so we need to pass arguments . we pass arguments like func_name(argument 1, argument 2 ,…) but how the arguments are being passed when we overloaded >> and << ? I cant see how the arguments are passed and recieved by overloaded functions. kindly explain in detail pls
How cin>>d; can call the overloaded operator >> as it is like a function so we need to pass arguments . we pass arguments like func_name(argument 1, argument 2 ,...) but how the arguments are being passed when we overloaded >> and <<?
I cant see how the arguments are passed and recieved by overloaded functions. kindly explain in detail pls
Hello @Rahulkr102
Like we use functions and send arguments to them like foo(arg1, arg2)
binary operators when overloaded send the left operand and the right operand as arguments.
like c1 = c2 + c3 where + is overloaded for c type objects, c2 and c3 are send as arguments.
These are different styles or syntax to achieve what we want in a readable format.
So in cin >> d it will send cin and d as left and right operands respectively.
But when + operator is overloaded we sent /passedonly one argument. Kindly refer the video .
You told binary operator send two arguments viz left and right.
Kindly explain in detailu
Yes the video’s correct.
One object (the left one) is the one whose method is being is called and the right one is passed as argument
Example
class C {
int data;
C operator+(const C& x) {// stuff}
}
int main() {
C c1, c2, c3;
c1 = c2 + c3
}
The above line c1 = c2 + c3 is equivalent to
c1.operator(c3)
Let me know if you still need any help.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.