Author | Message |
---|---|
jpascua
Posts: 197
|
Posted 14:46 Jan 31, 2015 |
So why exactly must they be implemented as a friend non-member function again? There's no need for automatic type casting. If you ask me, I feel like it's just a way to avoid the setters and getters. Am I right? |
kknaur
Posts: 540
|
Posted 14:58 Jan 31, 2015 |
Well they have to be overloaded as non member functions, because the first parameter to the function ALWAYS has to be the stream object (input or output). Since this is the case, if you were to overload the << and >> as member operators, that would mean the stream object can't be the first parameter. We make them friends to avoid having to use getters and setters, but you can still choose to make them nonmembers and nonfriends, but then you need to provide getters and setters. |
jpascua
Posts: 197
|
Posted 15:03 Jan 31, 2015 |
That makes sense. Thanks! |