c - "Error: unknown type name ..." while working on a 1st-class ADT fused with a 2nd-class ADT. -
good morning everybody.
i'm new here on so, , i'm asking question because have readjust algorithms , programming's exam of yesterday. while typing exam on codeblocks, got error couldn't fix. basically, exam asked load on memory infos file (format: char *namecity, int population, int distance) in data structure, , asked calculate mutual distances each city , collect them in data structure. decided make 2 adts: first defined in library "vett.h":
#ifndef vett_h_included #define vett_h_included #include "list.h" typedef struct vett { char nome[21]; int abitanti, dist; lista_t list; } item; item *vectinit(int n, item *v); item *vectinsert(item *v, char *nome, int people, int dist, int i); #endif // vett_h_included
i made "almost-adt" or "2nd class adt" (r.sedgewick) based on teacher lessons. doing so, main create array struct, , have direct access fields of struct; each "cell" contains: name of city, population, distance, , list-type field. problem begins here. calculate , save mutual distances of cities, decided make adt list, type 1st class, in library called "list.h" :
#ifndef list_h_included #define list_h_included #include "vett.h" typedef struct lista *lista_t; lista_t calculatemutualdistance(lista_t list, item *v, int n, int dist); int chechforbetter(int sd, int i, int n, item *v); lista_t listinit(lista_t list, int n); #endif // list_h_included`
the file "list.c" contains struct pointed in .h file:
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "list.h" typedef struct node *node; struct node { char destination[21]; int distance; node next; }; struct lista { node head, tail; }; (...)
now got error codeblocks (in vett.h, line 9, after int abitanti, int dist):
" error: unknown type name 'lista_t' ".
but why? lista_t contained in list.c file , should visible "vett.h", because included "list.h" , pointer finds struct in "list.c", has got "list.h" inclusion too!
hope can explain me, because have 2 days adjust program , make work, , it's quite huge. attention , sorry grammar errors, can tell i'm not english. have nice day!
it's typically forward declaration problem. change list.h file :
#ifndef list_h_included #define list_h_included typedef struct vett item; typedef struct lista *lista_t; lista_t calculatemutualdistance(lista_t list, item *v, int n, int dist); int chechforbetter(int sd, int i, int n, item *v); lista_t listinit(lista_t list, int n); #endif // list_h_included`
Comments
Post a Comment