<fabricemarchant@free.fr> wrote in message
news:1148246842.225455.310190@u72g2000cwu.googlegr oups.com...
: Please, could you give me hints about the way to define a ">>" operator
: to replace the "readObj" function of LISP objects ?
:
: // Main loop, in slf.c++
: while( notExitFlag )
: cout << *readObj( )->eval( top_env ) << '\n';
Since you're asking only about how to implement >>, I guess that you
have "implemented" << using a conversion to string ?
The proper way to define streaming operators is:
ostream& operator << ( ostream& s, MyClass const& obj ) { ... }
istream& operator >> ( istream& s, MyClass& obj ) { ... }
They are non-member functions. [ NB: both have to "return s;" ]
But you can declare them within the class, as friends, if
these functions need access to private members:
friend ostream& operator << ( ostream& s, MyClass const& obj );
friend istream& operator >> ( istream& s, MyClass& obj );
Amicalement --Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form