Hi folks,
I have the following code of which I don't understand why the reference 'q' doesn't work:
The Bloodshed Dev C++ linker said for the line:Code:#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int n;
cout<<"enter number of items: ";
cin>>n;
double *p = new double[n];
double &q = *p;
for (int i=0;i<n;i++) {
q[i] = i;
}
cout<<"The first item is: "<<q[0]<<endl;
cout<<"The last item is: "<<q[n-1]<<endl;
delete [] p;
system("PAUSE");
return EXIT_SUCCESS;
}
Code:q[i] = i;
However when I dropped the use of 'q', the program works fine. Is there anything wrong when I use a reference in such a context?Code:19 invalid types `double[int]' for array subscript
Thanks a lot in advance...