Hey Leute, ich treffe Dereferenzierung Zeiger auf unvollständige Art. es ist sehr seltsam. Ich brauche Graph.h // eine ungerichtete gewichteten Graphen Algorithmus SchnittstelleEin sehr seltsamer Fehler hier: Dereferenzierung Zeiger auf unvollständigen Typ
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 Hilfe // einen Teil der Umsetzung posten
#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 // einen Teil des Tests
#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;
}
ich bin so verwirrt, weil ich habe
typedef struct graphRep * Graph das heißt, es ist eine Struktur mit Zeiger. Aber noch diese Fehler bekam
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);
^
jemand mir helfen, T T
struct graphRep ist der Datei "testGraph.c" nicht bekannt. Wenn Sie Details von graphRep ausblenden möchten, können Sie das Opak-Pointer-Konzept verwenden. – rajesh6115