🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c++
Article #357

partial solution to cout << 'a' producing 97

#357
From: Mark Rafter
Date: Wed, 15 Oct 1986 16:15
29 lines
1380 bytes
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
Technical Details
Message-ID: <449@ubu.warwick.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!mcvax!ukc!warwick!rafter

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!mcvax!ukc!warwick!rafter
From: rafter@warwick.UUCP (Mark Rafter)
Newsgroups: net.lang.c++
Subject: partial solution to  cout << 'a'  producing 97
Message-ID: <449@ubu.warwick.UUCP>
Date: Wed, 15-Oct-86 12:15:48 EDT
Article-I.D.: ubu.449
Posted: Wed Oct 15 12:15:48 1986
Date-Received: Fri, 17-Oct-86 23:50:50 EDT
Reply-To: rafter@ubu.UUCP (Mark Rafter)
Organization: Computer Science, Warwick University, UK
Lines: 29