中午后好程序员,希望这是代码:
#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;
}
我的编译器说:“将'a'声明为引用数组”和:“'a'未声明(首先使用此函数)”我该如何解决?我有一个更大的代码,但我想知道如何在函数中引用数组知道我如何正确搜索我的问题解决方案
原始代码:
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;
}
}
}