cuốn sách gpt4 ai đã làm

c - Lỗi loại không đầy đủ cho struct|struct/union

In lại Tác giả: Vũ trụ không gian 更新时间:2023-11-04 02:46:00 27 4
mua khóa gpt4 Nike

我目前正在尝试基于哈希表构建字典。逻辑是:有一个名为 HashTable 的结构,其中包含以下内容:

HashFunc HashFunc;
PrintFunc PrintEntry;
CompareFunc CompareWords;
GetKeyFunc GetEntryKey;
DestroyFunc DestoryEntry;

这些是指向函数的指针(用户创建以制作模块化字典)。

_HashArray* HashArray;
int TableSize;

HashArray 是 _HashArray 对象的数组 -> 每个都是链表的第一个元素。TableSize 是 HashArray 的大小(我们能够创建的哈希值的数量)。

哈希.h:

typedef enum {FAIL = 0, SUCCESS} Result;
typedef enum {SAME = 0, DIFFERENT} CompResult;

typedef struct _Hash *pHash;

typedef void* pElement;
typedef void* pKey;

typedef int (*HashFunc) (pKey key, int size);
typedef Result (*PrintFunc) (pElement element);
typedef CompResult (*CompareFunc) (pKey key1, pKey key2);
typedef pKey (*GetKeyFunc) (pElement element);
typedef void (*DestroyFunc)(pElement element);

哈希.c

typedef struct _List
{
pElement _Element;
struct _List* listNext;
} pList;

cấu trúc typedef
{
pList* listFirst;
} _HashArray;

cấu trúc typedef
{
_HashArray* HashArray;
HashFunc HashFunc;
PrintFunc PrintEntry;
CompareFunc CompareWords;
GetKeyFunc GetEntryKey;
DestroyFunc DestoryEntry;
int TableSize;
} _Hash;

我正在尝试减速:

pHash HashCreate(int ArraySize, void* HashWord, void* PrintEntry, void* CompareWords, void* GetEntryKey, void* DestroyEntry)
{
// First set all function pointers
// Create the hashtable
pHash newTable = (pHash)malloc(sizeof(_Hash));
newTable->HashArray = (_HashArray*)malloc(sizeof(_HashArray)*ArraySize);
newTable->TableSize = ArraySize;
newTable->HashFunc = HashWord;
newTable->PrintEntry = PrintEntry;
newTable->CompareWords = CompareWords;
newTable->GetEntryKey = GetEntryKey;
newTable->DestroyEntry = DestroyEntry;
}

所有newTable->显示错误。

câu trả lời hay nhất

每个结构定义都需要一个名称。查看您对 _List 的定义:

typedef struct _List {
pElement _Element;
struct _List* listNext;
} pList;

以上等同于:

struct _List {
pElement _Element;
struct _List* listNext;
}

typedef struct _List pList;

对于所有的 struct/typedef 定义,您应该始终遵循上述格式之一。 _Hash 和 _HashArray 的 typdef 指的是未命名的结构。

typedef struct HashArray_struct_name_goes_here
{
pList* listFirst;
} _HashArray;

typedef struct Hash_struct_name_goes_here
{
_HashArray* HashArray;
HashFunc HashFunc;
PrintFunc PrintEntry;
CompareFunc CompareWords;
GetKeyFunc GetEntryKey;
DestroyFunc DestoryEntry;
int TableSize;
} _Hash;

关于c - 结构 |结构/union 的不完整类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27368417/

27 4 0
không gian vũ trụ
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress