Error message generated in the code


i had written this code according to the tutorials but idk where did i go wrong and all these errors appear.
Please help me in correcting this coed and finding out the mistake i made her.

hi @mvermav19, here’s the updated code https://ide.codingblocks.com/s/659427, commented the mistake

But why do we place that function outside the class??
Is it some kind of rule or some scope related issue??

@mvermav19,
In C++, stream insertion operator β€œ<<” is used for output and extraction operator β€œ>>” is used for input.
We must know the following things before we start overloading these operators.
1) cout is an object of ostream class and cin is an object of istream class
2) These operators must be overloaded as a global function. And if we want to allow them to access private data members of the class, we must make them friend.
Why these operators must be overloaded as global?
In operator overloading, if an operator is overloaded as a member, then it must be a member of the object on the left side of the operator. For example, consider the statement β€œob1 + ob2” (let ob1 and ob2 be objects of two different classes). To make this statement compile, we must overload β€˜+’ in a class of β€˜ob1’ or make β€˜+’ a global function.
The operators β€˜<<β€˜ and β€˜>>’ are called like β€˜cout << ob1’ and β€˜cin >> ob1’. So if we want to make them a member method, then they must be made members of ostream and istream classes, which is not a good option most of the time. Therefore, these operators are overloaded as global functions with two parameters, cout and object of user-defined class.

1 Like

ookay!
Got it now.
Thanks a lot

1 Like

@mvermav19, 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.