얘들 아 내가 불완전한 유형에 대한 역 참조 포인터를 만난다. 그것은 매우 이상합니다. 제가 Graph.h // 무향 그래프 가중 알고리즘 인터페이스아주 이상한 오류 여기에 : 불완전한 형식에 대한 포인터 역 참조
typedef int Vertex;
typedef struct {
Vertex v;
Vertex w;
int weight;
} Edge;
Edge mkEdge(Vertex, Vertex, int);
typedef struct graphRep *Graph;
Graph newGraph(int nV);
void insertE(Graph g, Edge e);
이 필요
Graph.c 구현의 일부를 남기 //
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "Graph.h"
struct graphRep {
int V;
int E;
int **edges;
}
int validV(Graph g, Vertex v);
int validV(Graph g, Vertex v){
return (v >= 0 && v < g->V);
}
// Create an edge from v to w
Edge mkEdge(Vertex v, Vertex w,int weight) {
assert(v >= 0 && w >= 0 );
Edge e = {v,w,weight};
return e;
}
Graph newGraph(int nV) {
assert(nV >= 0);
int i,j;
Graph g = malloc(sizeof(struct graphRep));
assert(g!=NULL);
if(nV==0){
g->edges = NULL;
} else {
g->edges = malloc(nV*sizeof(int *));
}
for(i = 0; i < nV;i++){
g->edges[i] = malloc(nV * sizeof(int));
assert(g->edges[i] != NULL);
for(j = 0; j < nV; j++){
g->edges[i][j] = 0;
}
}
g->V = nV;
g->E = 0;
return g;
}
시험
의 testGraph.c // 일부 내가 그것을 의미형식 정의 구조체 graphRep * 그래프 을했기 때문에
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "Graph.h"
int main(void){
printf("boundary test for newGraph\n");
Graph g = newGraph(0);
assert(g!=NULL);
assert(g->V == 0 && g->E ==0 && g->edges == NULL);
printf("test passed!\n");
free(g);
return 0;
}
나는 너무 혼란 스러워요 포인터가있는 구조체. 하지만 여전히 이러한 실수
wagner % gcc -Wall -Werror Graph.c testGraph.c
In file included from testGraph.c:3:0:
testGraph.c: In function 'main':
testGraph.c:30:12: error: dereferencing pointer to incomplete type
assert(g->V == 0 && g->E ==0 && g->edges == NULL);
^
testGraph.c:30:25: error: dereferencing pointer to incomplete type
assert(g->V == 0 && g->E ==0 && g->edges == NULL);
^
testGraph.c:30:37: error: dereferencing pointer to incomplete type
assert(g->V == 0 && g->E ==0 && g->edges == NULL);
^
누군가가 나에게 도움이있어 T T
"testGraph.c"파일에서 graphRep 구조체를 알 수 없습니다. graphRep의 세부 사항을 숨기려면 불투명 포인터 개념을 사용할 수 있습니다. – rajesh6115