whats going wrong here?? My >> and << overloading not working.
Operator Overloading
Hi @sounakume
While using operator overloading, you need to declare complex class object as const as the real and img variables are declared as private. Also, you need to use & sign with the return function signature and use the istream and ostream objects declared to take input. For eg: if you declare istream &is, then you need to write is>>c.real;
Here is the corrected code for your reference : https://ide.codingblocks.com/s/191496
Hope it Helps.
Here, in this case, why are we defining the functions outside of class?? While for others we are doing inside the class itself why is that? And also why did u declare them as friend fucntions?
Hi @sounakume
It doesn’t make a great difference between defining the functions inside and outside the class, but it is a good practice to write them outside the class. Also to enable these functions to use the private members of the class, we define the functions as friend functions.
Hope it Helps.