🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.ms-windows.programmer.tools
Article #504

Re: Use of const keyword - Borland container classes

#504
From: vincent
Date: Mon, 05 Oct 1992 15:00
51 lines
2388 bytes
In article <1992Oct1.215705.1396@aio.jsc.nasa.gov> bartels@sweetpea.jsc.nasa.gov (Jeff Bartels 283-4167) writes:
>
stuff deleted
>
>virtual int isSortable( const _FAR & Object ) const;
>My questions are: 
stuff deleted
>virtual const char *getPointer .....
stuff deleted
>this syntax, it did not complain when the code later modified the pointer value

Scott Meyers wrote an exelant book, called "Effective C++", now that a book!

Well about const before a reference/redirection char (&*), should mean that
what the ref./pointer is pointing/refe. to is not alowed to be modified. If
it's on the right (so after) of the (*,&) the pointer/ref. can't be modified.
Of course on both side it means that what it's pointing to and what it self
can't be modified.

As for after the function declaration, like somebody else wrote from JPL,
It says that the function is not alowed to modify stuff inside itself.
In the previously mentioned book in Item 21, 22 is a good discution
on the philosophy of const functions. (bitwise and conceptual constness)

Now writing: const char *get_a_pointer () would return a pointer to a char whichis can't be modified, but the pointer can.

Imagine a line going trough the asterix:

What's pointed to is constant |  Pointer is constant

			char  * pc		= get_a_pointer (); // error
		const	char  * pcc		= get_a_pointer ();
			char  * const cpc	= get_a_pointer (); // error
		const	char  * const cpcc	= get_a_pointer ();

(I don't know if my C++ translater is kapout but the first one gave a correct
error (i.e. expeted char *) but the line seven compiled (????)

1> const char *get_a_pointer () { char *c = new char; return c; }
2> 
3> main ()
4> {
5>		// char  * pc		= get_a_pointer (); // error
6>	const	char  * pcc		= get_a_pointer ();
7>		char  * const cpc	= get_a_pointer (); // error
8>	const	char  * const cpcc	= get_a_pointer ();
9>}

AnyWayByTheBook...

vincent@datmuc.dat.de
Technical Details
Message-ID: <1308@datmuc.UUCP>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!ira.uka.de!datmuc!vincent
References: <1992Oct1.215705.1396@aio.jsc.nasa.gov>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!ira.uka.de!datmuc!vincent
From: vincent@datmuc.UUCP (vincent)
Newsgroups: comp.os.ms-windows.programmer.tools
Subject: Re: Use of const keyword - Borland container classes
Message-ID: <1308@datmuc.UUCP>
Date: 5 Oct 92 15:00:34 GMT
References: <1992Oct1.215705.1396@aio.jsc.nasa.gov>
Followup-To: here
Organization: DAT
Lines: 54