why this code dosen't work ? ( &array in prototype)
arrays, c++, function, prototype, reference
Solution
Are you really trying to declare an array of references? If so, then you just can't.
If, however, you want to declare a reference to an array (which again I don't see the reason for in this particular case), then you have to parenthesize it because `[]` has higher precedence than `&`. Furthermore, in that case, you have to give a dimension to your array else it's a compiler error:
void sum(int (&a)[10])
{
// do stuff
}
Problem
good after noon programmers,hope are happy this is the code : ``` #include<iostream.h> void sum(int &a[]) { a[2] = a[1] +a[0]; } int main() { int a[3]={4,2,0}; sum(a); cout<<a[2]<<endl; } ``` my compiler say : "declaration of 'a' as array of references" and: "`a' undeclared (first use this function) " how i can fix that ? i have a bigger code but i want to know how to put array with reference in function i think it's problem in syntax and i don't know where i find the solution so i come here i search a lot on internet but i don't know how i search right for my problem solution the original code : ``` void Jump(int &y,int &y0, float V0 ,float &time, int &ground , int radius , int thickness_of_ground ,bool &protect_from_jump ,bool &ready_for_jump , bool (&key)[5]) { int SPACE=4; float a_y=9.8; int FPS =60; if (protect_from_jump) key[SPACE]=false; if(!key[SPACE] && ground-(radius+thickness_of_ground)-y>0) { V0=0; y=int(0.5*a_y*time*time -V0*time + y0); time +=6.0/FPS; protect_from_jump=true; } else if (!key[SPACE] && ground-(radius+thickness_of_ground)-y<=0) { y=ground -(radius+thickness_of_ground); y0=y; time=0; protect_from_jump=false; } if(key[SPACE]) { if (ready_for_jump) { y0=y; ready_for_jump = false; } V0=40; y=int(0.5*a_y*time*time -V0*time + y0); time +=6.0/FPS; if(ground-(radius+thickness_of_ground)+1-y<=0) { ready_for_jump=true; y=ground-(radius+thickness_of_ground); y0=y; time=0; key[SPACE]=false; } } ``` }