I suspect that is not actually what the OP was hoping for. The problem
is that within the definition of S the compiler needs actual types. In
this simple example there is only one instance of S and so the C trick
will work. However, it ceases to be useful if we want more than one
instance of S with different size arrays.
The answer is that such cannot be done without templates (or some
equivalent from C++11) because each size array is a different type and
so references to them are also different types. At the point of
definition of the struct the members must be identifiable types. A
template gets round this by creating a family of types with the same
basic name refined by the actual types in use.
struct S {
const int (&values)[2];
};
struct S {
const int (&values)[3];
};
struct S {
const int (&values)[4];
};
struct S {
const int (&values)[5];
};
Are all different types that can only share a name via templates where
the names might be refined to:
S<2>, S<3>, S<4>, S<5>
I sometimes describe a class template as providing the 'family name' for
a group of loosely related (by behaviour) types that will need the
addition of a 'personal name'.
The problem with the OP's original code is that at the point of
definition of S the compiler has no way to know which member of the
family is being defined. By the time the instance s is defined it is too
late.
Francis
>