出现莫名的"subscript requires array or pointer type"错误

zjut_112 2006-08-22 09:27:53
代码如下:
这是一个最短路径的代码,其中用了一个二维数组的指针,不知道是怎么回事,还请大家指点指点,谢谢了
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;
}
}
}
}


}
...全文
836 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjut_112 2006-08-22
  • 打赏
  • 举报
回复
大意了,太谢谢了
Roxxette 2006-08-22
  • 打赏
  • 举报
回复
for(i=0;i<n;i++)
{
int temp=max; //temp 重定义了
int u=v;
for(int j=0;j<n;j++)

65,183

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧