出现莫名的"subscript requires array or pointer type"错误
代码如下:
这是一个最短路径的代码,其中用了一个二维数组的指针,不知道是怎么回事,还请大家指点指点,谢谢了
void shortpath(struct TraTool Tools[],char* start,char* end,char* city[],int tn,int cn,int choice)
{
int i,j,k;
int (*temp)[10];
float max=65536;
int n=cn;
int* dist=new int[n];
int* prev=new int[n];
bool* s=new bool[cn];
switch(choice)
{
case 11:
temp=traintime;break;
case 12:
temp=trainprice;break;
case 21:
temp=flighttime;break;
case 22:
temp=flightprice;break;
printf("Error Choice!\n");break;
}
for(i=0;i<n;i++)
{
dist[i]=temp[v][i];//源点到各点的距离
s[i]=false;
if(dist[i]==max)prev[i]=0;
else prev[i]=v;
}
dist[v]=0;
s[v]=true;
for(i=0;i<n;i++)
{
int temp=max;
int u=v;
for(int j=0;j<n;j++)
if((!s[j])&&(dist[j]<temp))
{
u=j;
temp=dist[j];
}
s[u]=true;
for(j=0;j<n;j++)
{
if((!s[j])&&(temp[u][j]<max))//此行出错
{
int newdist=dist[u]+temp[u][j];//此行出错
if(newdist<dist[j])
{
dist[j]=newdist;
prev[j]=u;
}
}
}
}
}