a note on operator>> and operator<<
29 Jan
2009
29 Jan
'09
6:30 p.m.
The correct way to have operator<< and operator>> work for reading and writing a class is to declare them as functions in the namespace containing the object. Declaring them as member functions does something else entirely (or absolutely nothing useful, depending on how you do it). The problem is that the compiler searches for operators by checking member functions of the left hand object (for i/o it is the stream itself), then the current namespace and the namespaces containing the arguments. It never looks for member functions of the right hand type.
I suggest implementing operator>> as:
struct Mine { void show(std::ostream &out=std::cout) const; };
IMP_OUTPUT_OPERATOR(Mine)
5804
Age (days ago)
5804
Last active (days ago)
0 comments
1 participants
participants (1)
-
Daniel Russel