[英]error C2065: 'Test_Proc' : undeclared identifier which 'Test_Proc' already exists
[英]Unable to fix the Error code C2065 'Bucket': undeclared identifier
我的代码有问题。 我收到一条错误消息说。 严重性代码说明项目文件行抑制状态错误 C2065“桶”:未声明的标识符。 但是问题是我定义了Bucket。 你们中的任何一个人会检查出什么问题了吗? 我正在处理的代码是一个代码框架。
在这里你得到这两个重要的代码。
Ps:对不起我的英语,这不是我的母语所有翻译都来自谷歌翻译
#ifndef BUCKET_H
#define BUCKET_H
#include "Person.h"
typedef Person Value;
typedef int Key;
struct Bucket
{
Key key;
Value value;
};
#endif
#define _CRT_SECURE_NO_WARNINGS // Behovs for vissa funktioner i visual studio
#include "HashTable.h"
#include "Bucket.h"
#include<assert.h>
#include<stdlib.h>
#include<stdio.h>
/* Denna funktion tar en nyckel och returnerar ett hash-index
dvs ett index till arrayen som Šr Hashtabellen */
static int hash(Key key, int tablesize)
{
return key % tablesize;
}
/*Leta framŒt enligt principen šppen adressering
Antalet krockar returneras via pekaren col i parameterlistan*/
static int linearProbe(const HashTable* htable, Key key, unsigned int *col)
{
int index;
index = hash(key, htable->size);
int i;
for (i = 0; i < htable->size; i++) {
if (htable->table[index].key == key) {
return index;
}
index = (index + 1) % htable->size;
}
*col = i;
return -1;
}
/*Allokera minne fšr hashtabellen*/
HashTable createHashTable(unsigned int size)
{
HashTable htable;
htable.table = calloc(size, sizeof(Bucket));
htable.size = size;
return htable;
}
/* Satter in paret {key,data} i Hashtabellen, om en nyckel redan finns ska vardet uppdateras */
/* Returnerar antalet krockar (som rŠknas i linearProbe() )*/
unsigned int insertElement(HashTable* htable, const Key key, const Value value)
{
unsigned int col = 0;
int index = linearProbe(htable, key, &col);
if (index >= 0) {
htable->table[index].value = value;;
return col;
}
htable->table[index].value = value;
return col;
}
/* Tar bort datat med nyckel "key" */
void deleteElement(HashTable* htable, const Key key)
{
unsigned int col = 0;
int index = linearProbe(htable, key, &col);
if (index >= 0) {
htable->table[index].key = 0;
}
}
/* Returnerar en pekare till vardet som key ar associerat med eller NULL om ingen sadan nyckel finns */
const Value* lookup(const HashTable* htable, const Key key)
{
unsigned int col = 0;
int index = linearProbe(htable, key, &col);
if (index >= 0) {
return &htable->table[index];
}
return NULL;
}
/* Tommer Hashtabellen */
void freeHashTable(HashTable* htable)
{
free(htable->table);
free(htable);
}
/* Ger storleken av Hashtabellen */
unsigned int getSize(const HashTable* htable)
{
return htable->size;
}
/* Denna for att ni enkelt ska kunna visualisera en Hashtabell */
void printHashTable(const HashTable* htable)
{
for (int i = 0; i < htable->size; i++) {
printPerson(&htable->table[i], i);
}
}
您声明一个名为“struct Bucket”的结构,如下所示:
struct Bucket
{
Key key;
Value value;
};
但是你这样引用它:
htable.table = calloc(size, sizeof(Bucket));
没有称为“Bucket”的类型,只有“struct Bucket”。 如果你想做那样的事情,最好有:
typedef struct
{
Key key;
Value value;
} Bucket;
如果您只是像这样对其进行类型定义,则可以使用匿名结构,即您不需要将结构标记为“struct Bucket”。
另一种方法是始终将其称为“struct Bucket”,例如:
htable.table = calloc(size, sizeof(struct Bucket));
我认为您的代码可能会在 C++ 中编译,这允许在引用类型时删除“结构”,但您已将其标记为 C。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.