[comp.lang.c++] array of references

peter@mit-amt.MEDIA.MIT.EDU (Peter Schroeder) (10/22/89)

How do you make an array of references? Is it possible?

typedef int& iref;

funk()
{
   int i = 1;
   int* &m = &i; // works; but this is a reference to a pointer

   int& j = i;
   int& *M = &j; // ERROR

   iref J = i;
   iref *N = &J; // this however works... (as expected)
                 // but that is not quite what I want...
}

what I really want is this

Funk()
{
   int i = 1;
   int& j = i;  // easy! Now, what is the array version of this?

   static int& M[] = { i, i }; // ??? this don't work
}


cfront 1.2.1 will accept this however:

FUnk()
{
	int i = 1;
	static int N[2] = { i, i };
}

but produces bad C code!


Anyway, I have these giant structures, a whole bunch (array) of which I want
to send to a function. However the actual structures are all over the
program, so I can't initially allocate them in an array. I want an array of
references...! How do I do it?

Thanks for your help!

Peter
peter@media-lab.media.mit.edu