Pedantically, the reason why arrays of references are illegal is because the Standard explicitly forbids them.
C++03:8.3.2/4
There shall be no references to references, no arrays of references,
and no pointers to references.
Emphasis mine.
One reason the Standard explicitly forbids arrays of references (maybe there are more) is because of how arrays are indexed. Suppose you do:
Gizmo& gizmos[] = {...};
Gizmo&* g3 = &gizmos[2];
There are several things wrong here. First you have a pointer to a reference, which is illegal. Second, in order to evaluate gizmos[2]
the compiler must do an implicit conversion-to-pointer, and then do pointer arithmetic based on that. How big is a Gizmo&
?
According to the Standard, the sizeof
a reference is, itself, unspecified. However when sizeof
is applied to a reference, the result is the size of the referred-to type.
C++03:5.3.3/2 Sizeof
When applied to a reference or a reference type, the result is the
size of the referenced type.
Try running this code and see what happens:
#include <iostream>
#include <iomanip>
using namespace std;
struct Gizmo { int n_[100]; };
int main()
{
typedef Gizmo& GR;
size_t n = sizeof(GR);
cout << n << endl;
}
When I run this on my machine, (MSVC10, Win7x64), the result is 400.
This is why arrays of references are illegal.