C++ 错误:指向算术中使用的函数的指针

C++ 错误:指向算术中使用的函数的指针,c++,C++,我正在尝试编写Prim的算法。然而,当我编译时,我在第57、59、60、62、63、65行上得到了错误 显然这和我的数组有关。。。我只是不知道到底是什么。我有种感觉,这与我试图找出但失败的指针有关 int map[][7]是一个全局数组,我正在使用它跟踪我的初始图形 编辑-根据要求,这里是所有代码 #include <iostream> using namespace std; void performPrims(int); void print(int *); // Glob

我正在尝试编写Prim的算法。然而,当我编译时,我在第57、59、60、62、63、65行上得到了错误

显然这和我的数组有关。。。我只是不知道到底是什么。我有种感觉,这与我试图找出但失败的指针有关

int map[][7]是一个全局数组,我正在使用它跟踪我的初始图形

编辑-根据要求,这里是所有代码

#include <iostream>

using namespace std;

void performPrims(int);
void print(int *);

// Global Variables
int nodes = 7;
int cur   = 0;
int cost  = 0;

int map[][7] =  
   {{0,3,6,0,0,0,0},
    {3,0,7,0,0,12,0},
    {6,7,0,10,13,8,0},
    {0,0,10,0,0,0,5},
    {0,0,13,0,0,9,4},
    {0,12,8,0,9,0,11},
    {0,0,0,5,4,11,0}};

int main()
{
// Initializations

srand(time(NULL)); 
int S = rand() % 7; // Create an arbitrary starting point

// Perform Prim's Algorithm starting with S

performPrims(S);

return 0;
}

void performPrims(int S)
{
int low = 100;

// open[] is used to keep track of what vertices are available
int open [] = {1,2,3,4,5,6,7};

// closed [] is used to keep track of what vertices have been reached and in what order
int closed [] = {0,0,0,0,0,0,0};

open [S] = 0;       // Make our starting node unavailable
closed [cur] = S+1; // Record our starting node in the path
cur++;

while (cur < 7)
{
    int i=0;
    while (i<nodes)
    {
        int k=0;
        while (k<nodes)
        {
            if (*map[*close[i]-1][k] > 0 && *map[*close[i]-1][k] < low)
            {
                low = map[close[i]-1][k];
                close [cur] = k+1;
            }
            map[close[cur-1]-1][close[cur]-1] = 0;
            map[close[cur]-1][close[cur-1]-1] = 0;
            cost += low; low = 100;
            open[close[cur]-1] = 0;
            k++;
        }
        i++;
    }
    cur++;
}
print(closed);
}

void print(int *closed)
{
cout<<"The path taken was ";
for (int i=0; i<nodes; i++)
    cout<<closed[i]<<" "<<endl;
cout<<"\nThe cost is "<<cost<<endl;
}
#包括
使用名称空间std;
无效性能边缘(int);
空白打印(整数*);
//全局变量
int节点=7;
int cur=0;
整数成本=0;
int map[][7]=
{{0,3,6,0,0,0,0},
{3,0,7,0,0,12,0},
{6,7,0,10,13,8,0},
{0,0,10,0,0,0,5},
{0,0,13,0,0,9,4},
{0,12,8,0,9,0,11},
{0,0,0,5,4,11,0}};
int main()
{
//初始化
srand(时间(空));
int S=rand()%7;//创建任意起点
//从s开始执行Prim算法
绩效考核;
返回0;
}
无效性能测试(int S)
{
int低=100;
//open[]用于跟踪哪些顶点可用
int open[]={1,2,3,4,5,6,7};
//closed[]用于跟踪已到达的顶点及其顺序
int closed[]={0,0,0,0,0,0};
打开[S]=0;//使起始节点不可用
closed[cur]=S+1;//在路径中记录我们的起始节点
cur++;
而(cur<7)
{
int i=0;

而(i您拼错了
close
。您键入了
close

close
的所有实例替换为
closed


另外,将
#include
添加到文件的顶部。

猜测第57行是示例的第一行,然后看起来是
close
导致了问题。您能否向我们展示所有相关的代码和错误消息?这些变量是如何定义的?确切的错误是什么?我想您的问题是您正在使用g
close
当你指的是
close
时,这很尴尬……但谢谢你。我希望我能送你一盒甜甜圈或甜甜圈
,他需要删除'if(*map[*close[I]-1][k]>0&*map[*close[I]-1][k]*
`我已经删除了*。谢谢。现在我只需要让代码正常工作。您还应该使用比
rand
更好的东西(或者修改您当前的实现)。将模与rand一起使用是不好的,请参阅