首页 文章

“错误:未知类型名称......”在使用第二级ADT进行融合的一流ADT时 .

提问于
浏览
2

大家早上好 .

我是新来的,所以我问这个问题,因为我必须重新调整昨天的算法和编程考试 . 在CodeBlocks上输入我的考试时,我收到了一个我无法解决的错误 . 基本上,考试要求在数据结构中从文件(格式:char * namecity,int population,int distance)加载内存中的一些信息,然后要求计算每个城市的相互距离并将其收集到另一个数据中结构体 . 我决定制作2个ADT:第一个在我的库“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

根据我的老师课程,我做了“几乎ADT”或“二等ADT”(R.Sedgewick) . 这样做,main可以为该结构创建一个数组,并且可以直接访问该结构的字段;每个“单元格”包含:城市名称,人口,距离和列表类型字段 . 问题从这里开始 . 为了计算和保存城市的相互距离,我决定在名为“List.h”的库中创建另一个ADT列表,输入第一类:

#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`

文件“List.c”包含.h文件中指向的结构:

#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;
};

(...)

现在我从CodeBlocks得到了这个错误(在vett.h,第9行,在int abitanti之后,int dist):

“错误:未知类型名称'lista_t'” .

但为什么? lista_t包含在List.c文件中,应该在“vett.h”中完全可见,因为我包含了“List.h”,指针在“List.c”中找到了它的结构,它有“List.h”包容呢!

希望有人可以向我解释,因为我只有2天时间来调整程序并使其工作,而且它非常庞大 . 感谢您对我的语法错误的关注和抱歉,因为您可以说我不是英语 . 祝你今天愉快!

1 回答

  • 0

    这通常是一个前向声明问题 . 只需像这样更改List.h文件:

    #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`
    

相关问题