rafter@warwick.UUCP (Mark Rafter) (10/15/86)
If you add the following (Steve Rumsby's idea):
ostream& put(char); // put('a') writes a
ostream& operator<<(const char &c){ return this->put(c);}
to the class ostream BEFORE the declaration of the operator
ostream& operator<<(int a) { return *this<<long(a); }
and delete the original declaration of put(char) , then the program:
#include <stream.h>
main()
{
char b = 'b';
cout << char('a') << b;
}
will output ``ab'' rather than ``9798''. However there are the following
(related) quirks:
1 the order of the declarations is important
2 the new << operator must be a member of ostream
I cannot find any justification for these two points in the C++ book -
is there any?
----------------------------------
Mark Rafter, Computer Science, Warwick Univ, Coventry CV4 7AL, ENGLAND
..!ukc!warwick!rafter +44 203 523364