【发布时间】:2016-04-06 20:57:02
【问题描述】:
您好,我正在尝试将名为 hash_entry 的结构添加到另一个结构 (hash_table) 内的 hash_entry 数组中,但我收到此错误:
hash.c:67:5: error: invalid use of undefined type ‘struct hash_entry’
my_table->table[0] = e;
^
hash.c:67:30: error: dereferencing pointer to incomplete type
my_table->table[0] = e;
我的结构:
typedef struct hash_entry{
int value;
} Hash_entry;
typedef struct hash_table{
struct hash_entry * table;
} Hash_table;
我的代码将内存分配给数组并添加:
Hash_entry e;
e.value = 10;
Hash_table *my_table = (Hash_table *) malloc(sizeof (Hash_table));
my_table->table = malloc (sizeof (Hash_entry) * 10);
my_table->table[0] = e;
【问题讨论】:
-
为什么你的类型和变量有相同的名字?你会取得什么成就?
标签: c arrays pointers struct malloc