Re: Reference to void
Alf P. Steinbach wrote:
* James Kanze:
Lucian Radu Teodorescu wrote:
Salt_Peter wrote:
Is the following code valid?
int i = 5;
void* pv = &i;
void& rv = *pv; // Error here on VC 2005
If not, why isn't it valid?
Its not valid for the same reasons that the following is invalid:
void v = 5;
That is to say: a reference is an object and a valid object.
The same can't be said of a pointer, or any pointer.
Let's make the following assumption: every type is implicitly derived
from void. Many C++ programmers can accept that.
Name one. It's manifestly false; it is, in fact, illegal to
derive from void (or from any incomplete type).
Note that Lucian (as I read that article, especially in light
of the rest of it) was describing a future extension, not the
current language.
I understand that. He also makes some assumptions with regards
to the current language, to argue that the extention is
intuitively natural, and would easily fit into the current
language.
I can easily see some interest in such an extension. They way
he describes it, however (all types deriving from void) isn't
compatible with the way the current language is described, and
would require a major rework of the standard (even if the
effective results for the user are the same).
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]