我有以下代码:
typedef struct AdjMatrix
{
int nodes;
int **adjMat;
} graph;
typedef struct Edge
{
int from,to,weight;
}Edge;
int main(){
...
graph *g=(graph *)malloc(sizeof(graph));
g-> adjMat = (int **)malloc(sizeof(int *) * vertices);
for( i = 0; i < vertices; i++){
g->adjMat[i] = (int *)malloc(sizeof(int) * vertices);
}
...
Edge *E = (Edge *)malloc(sizeof(Edge) * maxEdges);
int nEdges = 0;
for(i = 0; i < g->nodes ; i++){
for(j= 0; j< g->nodes; j++){
if(i <= j){
printf("%d\t%d\t%d\t\n",i,j,g->adjMat[i][j]);
E[nEdges].from = i;
E[nEdges].to = j;
E[nEdges].weight = g->adjMat[i][j];
nEdges++;
}
else
break;
}
}
}
如您所见,我通过“->”访问图 g 的元素,通过“.”访问 Edge E 的元素。如果我通过“。”访问图 g 的元素,我不明白为什么编译器会抛出错误。或边缘 E 的元素由“->”?请解释