On Nov 21, 5:33 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
[...]
Quote:
Your understanding can be seen as correct. However, the situation
is simpler: arrays of references are prohibited by the language
(see Standard, [dcl.ref]/4). The Standard does not explain why no
arrays of references shall exist, just says there shall be none.
More generally, the standard says that references are not
objects. The fact that you cannot have an array of references
stems directly from that.
The fact that references are not objects means that they have
neither an address nor a size. (Taking the address of a
reference results in the address of the referred to object, and
sizeof a reference type is the size of the referred to type.) C
style arrays require pointer arithmetic to work, and pointer
arithmetic implies that the objects in the array have an address
and a size. (How could the array convert implicitly to the
address of the first element, if that element didn't have an
address.) The standard containers (std::vector, etc.) are
designed to contain objects as well. It's never stated as a
required concept that the objects be addressable, because by
definition, all objects are addressable. But they obviously
cannot be made to work if the elements aren't addressable or
don't have a known constant size.
Quote:
It's possible to speculate and find a logical explanation as
to why no arrays of references are allowed, but it's not
really a good use for our time.
It's perhaps useful to understanding to show that the
restriction is coherent with the overall definition of
references, and not just an arbitrary restriction.
The choice that references not be objects is perhaps arbitrary,
but once the standard made that choice, a lot of other
restrictions follow automatically.
--
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