我有以下的.h和.cpp文件无法解析的外部错误
如果非要我将包括功能的完整代码的定义
当我编译我的程序,我得到在所示的错误结束
hash.h
#define BUCKETS 64
#define B_ENTRIES 50000
int curr_tanker;
typedef unsigned long int ulong;
typedef struct bucket
{
int bucket_id;
ulong bucket_entries;
}bucket;
typedef struct tanker_record
{
ulong tanker_id;
ulong tanker_size;
ulong num_of_entries;
ulong bucket_entry_count;
}tanker_record;
typedef struct fpinfo
{
unsigned long chunk_offset;
unsigned long chunk_length;
unsigned char fing_print[33];
}fpinfo;
struct fpinfo* InitHTable(fpinfo *);
int CreateTanker(tanker_record tr[]);
int Hash_CreateEntry(struct fpinfo *,struct fpinfo he,tanker_record tr);
ht.cpp
#include <stdlib.h>
#include <string.h>
#include<stdio.h>
#include <iostream>
#include "ht.h"
struct fpinfo* InitHTable(struct fpinfo ht[][B_ENTRIES])
{
}
int CreateTanker(tanker_record tr[])
{
}
int
Hash_CreateEntry(struct fpinfo *t[][B_ENTRIES],struct fpinfo he,tanker_record tr[])
{
}
static void
WriteHTtoFile(struct fpinfo *t[][B_ENTRIES],int this_tanker)
{
}
的main.cpp
#include<iostream>
#include"ht.cpp"
#include<conio.h>
#include<stdlib.h>
void main(int argc, char **argv)
{
static fpinfo hash_table[BUCKETS][B_ENTRIES];
static tanker_record tr[100];
InitHTable(&hash_table[0][0]);
CreateTanker(tr);
struct fpinfo fp;
...
ar = Hash_CreateEntry(&hash_table[0][0], fp,tr[0]);
我碰到下面的错误,当我尝试使用VC2010
1> main.obj编译它:错误LNK2005:“结构fpinfo * __cdecl InitHTable(结构已经在ht.obj中定义了fpinfo(* const)[50000])“(?InitHTable @@ YAPAUfpinfo @@ QAY0MDFA @ U1 @@ Z)
1> main.obj:error LNK2005:”int __cdecl CreateTanker tanker_record * const)“ (?CreateTanker @@ YAHQAUtanker_rec ord @@@ Z)已经在ht.obj中定义了
1> main.obj:error LNK2005:“int __cdecl Hash_CreateEntry(struct fpinfo *(* const)[50000],struct fpinfo,struct tanker_record * const)” (?Hash_CreateEntry @@ YAHQAY0MDFA @ PAUfpinfo @@ U1 @ QAUtanker_record @@@ Z)已经在ht.obj中定义了 1> main.obj:错误LNK2005:“int curr_tanker”(?curr_tanker @@ 3HA)已经在ht中定义。 obj 1> main.obj:错误LNK2019:无法解析的外部符号“int __cdecl Hash_CreateEntry(struct fpinfo *,struct fpinfo,struct tanker_record)” (?Hash_CreateEntry @@ YAHPAUfpinfo @@ U1 @ Utanker_record @@@ Z) _main 1> main.obj:error LNK2019:无法解析的外部符号“struct fpinfo * __cdecl InitHTable(struct fpinfo *)”(?InitHTable @@ YAPAUfpinfo @@ PAU1 @@ Z)主
感谢您的帮助!
这是我最初做的,但它仍然给最后三个错误。它只能避免前两个“lnk2005”的错误 – John 2012-02-27 12:57:46
@John:哦,是的,当我读错误时,我的眼睛一定已经看到了。这是因为声明与定义不匹配 - 声明具有指向对象的参数,而定义具有指向数组的指针。 – 2012-02-27 13:02:46
谢谢。但是函数调用的正确语法是什么?第一个创建错误**错误C2664:'InitHTable':无法将参数1从'fpinfo *'转换为'fpinfo * [] [50000]'**和**错误C2664:'Hash_CreateEntry':无法将参数1从'fpinfo *'到'fpinfo * [] [50000]'** – John 2012-02-27 13:18:15