🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: type casting and const

#71
From: aglew
Date: Fri, 07 Mar 1986 03:14
28 lines
1845 bytes
>/* Written  6:12 pm  Mar  4, 1986 by trl@cbrma.UUCP in ccvaxa:net.lang.c++ */
>/* ---------- "type casting and const" ---------- */
>
>	I have a class, "string", that can be converted to "char*".  I
>want the converted object to be "readonly", i.e. "const".  I have been
>using "operator char* ()", but would like to know if there is a way
>to get "const char*".  I do not want to use intermediate types since
>I want to use "string" and "const char*" together without explict type
>casting.  Any help would be appreciated, thanks.
>-- 
>
>  Tom Lanning   AT&T Bell Laboratories   Columbus OH   43213     614-860-4153
>/* End of text from ccvaxa:net.lang.c++ */

This raises another interesting point: is it possible to require 
read-only-ness as part of the description of the type to which a pointer
refers? Verbosely "pointer to const int", *(const int), so that 
	int i;
	const int j = 666;
	int *pv;
	const int *pc;			// or something like
	pv = &i;  *pv = 1;	//succeeds
	pv = &j;  *pv = 2;	// should fail, perhaps at compile time?
	pc = &i;  *pc = 3;	// should fail AT COMPILE TIME
	pc = &j;  *pc = 4;	// ditto.

Or is the only way to define a new class, overloading assignment, etc?
Technical Details
Message-ID: <47900004@ccvaxa>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!ihnp4!inuxc!pur-ee!uiucdcs!ccvaxa!aglew
References: <4187@cbrma.UUCP>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: Notesfiles $Revision: 1.7.0.10 $; site ccvaxa
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!ihnp4!inuxc!pur-ee!uiucdcs!ccvaxa!aglew
From: aglew@ccvaxa.UUCP
Newsgroups: net.lang.c++
Subject: Re: type casting and const
Message-ID: <47900004@ccvaxa>
Date: Thu, 6-Mar-86 22:14:00 EST
Article-I.D.: ccvaxa.47900004
Posted: Thu Mar  6 22:14:00 1986
Date-Received: Sat, 8-Mar-86 23:02:57 EST
References: <4187@cbrma.UUCP>
Lines: 28
Nf-ID: #R:cbrma.UUCP:4187:ccvaxa:47900004:000:1190
Nf-From: ccvaxa.UUCP!aglew    Mar  6 21:14:00 1986