error: invalid use of undefined type ‘struct Item’
error: invalid use of undefined type ‘struct Item’
这是相关的结构。请注意,它们在同一文件的 header 中。
typedef enum {AAA = 0, BBB = 1, CCC = 2, DDD = 3} Subject;
typedef struct item {
Subject sub;
int n, h;
char title[1024];
} Item;
struct Item* Collection = NULL;
在 main 中,我为 Collection:
分配了 space
Collection = malloc(sizeof(Item*));
然后在我的 main 中有一个调用 insert() 函数的 switch 语句该函数如下:
void course_insert() {
Collection = realloc(Collection,(sizeof(Collection) + sizeof(Iem)));
printf("What is the subject? (AAA=0, BBB=1, CCC=2, DDD=3)? ");
scanf("%u", Collection[count].sub);
printf("What is the number (e.g 20)? ");
scanf("%d", Collection[count]->n);
printf("How many hours (e.g. 3)? ");
scanf("%d", Collection[count]->h);
printf("What is the name of the item? ");
scanf("%s", Collection[count]->title);
count++;
}
我收到一条错误消息,指出这是对未定义类型的无效使用 'struct Item',但我可以在其他地方正常使用它。谁能找出问题所在?
typedef
语句表示typedef
struct item
Item
。这意味着您定义了 struct item
和 Item
但没有定义 struct Item
。尝试使用 struct item
或 Item
.
这是相关的结构。请注意,它们在同一文件的 header 中。
typedef enum {AAA = 0, BBB = 1, CCC = 2, DDD = 3} Subject;
typedef struct item {
Subject sub;
int n, h;
char title[1024];
} Item;
struct Item* Collection = NULL;
在 main 中,我为 Collection:
分配了 spaceCollection = malloc(sizeof(Item*));
然后在我的 main 中有一个调用 insert() 函数的 switch 语句该函数如下:
void course_insert() {
Collection = realloc(Collection,(sizeof(Collection) + sizeof(Iem)));
printf("What is the subject? (AAA=0, BBB=1, CCC=2, DDD=3)? ");
scanf("%u", Collection[count].sub);
printf("What is the number (e.g 20)? ");
scanf("%d", Collection[count]->n);
printf("How many hours (e.g. 3)? ");
scanf("%d", Collection[count]->h);
printf("What is the name of the item? ");
scanf("%s", Collection[count]->title);
count++;
}
我收到一条错误消息,指出这是对未定义类型的无效使用 'struct Item',但我可以在其他地方正常使用它。谁能找出问题所在?
typedef
语句表示typedef
struct item
Item
。这意味着您定义了 struct item
和 Item
但没有定义 struct Item
。尝试使用 struct item
或 Item
.