| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3270 人关注过本帖
标题:subscript requires array or pointer type
只看楼主 加入收藏
heyyroup
Rank: 1
等 级:新手上路
帖 子:77
专家分:0
注 册:2006-6-14
收藏
 问题点数:0 回复次数:1 
subscript requires array or pointer type
在写最短路径算法的时候出现问题:subscript requires array or pointer type
算法的代码我贴出来,希望大家帮我看看是哪里出错了.
void Graph::ShortestPath(VertexType & v)
{
    int pos=GetVertexPos(v);  //取得顶点值为v在数组中的位置
    for(int i=0;i<NumVertices;i++)    //NumVerteces为图中的结点个数
    {
        dist[i]=Matrix[pos][i];                 //邻接矩阵的第pos行元素复制到dist中
        WeightFound[i]=0;                   //已求出最短路径的顶点集合初始化
        if(i!=pos&&dist[i]<MaxNum)
            path[i]=pos;
        else
            path[i]=-1;                         //路径存放数组初始化
    }
    WeightFound[i]=1;                     //将顶点v加入到顶点集合
    dist[pos]=0;
    for(i=0;i<NumVertices-1;i++)
    {
        double min_value=MaxNum;
        int u=pos;
        for(int j=0;j<NumVertices;j++)
            if(!WeightFound[j]&&dist[j]<min_value)
            {
                u=j;
                min_value=dist[j];
            }
        WeightFound[u]=1;
        for(int w=0;w<NumVertices;w++)
            if(!WeightFound[w]&&(dist[u]+MaxNum[u][w]<dist[w]))
            {
                dist[w]=dist[u]+Matrix[u][w];
                path[w]=u;
            }
    }
   
}
在红色代码出编译的时候提示出现错误
dist[],path[],weightFound[]是在类Graph里面定义的
搜索更多相关主题的帖子: array pointer requires subscript type 
2007-12-04 14:22
heyyroup
Rank: 1
等 级:新手上路
帖 子:77
专家分:0
注 册:2006-6-14
收藏
得分:0 
搞定了,笔误笔误,我把数组的名字Matrix写成MaxNum,难怪出错.
2007-12-04 14:44
快速回复:subscript requires array or pointer type
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013785 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved