srwmrbd@windy.dsir.govt.nz (ROBERT) (04/16/89)
// example of incorrect output from zortech version 1.07 // when << is extended to structures #ifdef ZORTECH #include <stream.hpp> #else #include <xstream.hxx> #endif class ExtInt { int value; public: ExtInt operator+(ExtInt&); friend ostream& operator<<( ostream&, ExtInt& ); ExtInt(int v) { value=v; } }; main() { ExtInt a1=15; ExtInt a2=3; cout << a1 <<" "<< a2 <<"\n"; cout << a1+a1 <<" "<< a1+a2 <<"\n"; // produces incorrect output cout << a1+a1 <<" "; cout << a1+a2 <<"\n"; // produces correct output } ExtInt ExtInt::operator+(ExtInt& er) { return ExtInt(value+er.value); } ostream& operator<<(ostream& os, ExtInt& er) { os << er.value; return os; }