【发布时间】:2012-04-12 12:05:31
【问题描述】:
我正在尝试在一些带有标头类的文件中包含一个简单的哈希表类。但是每当我尝试编译时,我都会遇到几个这样的错误:
LNK2019:函数 _main 中引用的未解析的外部符号“public: __thiscall HashTable::~HashTable(void)”(??1HashTable@@QAE@XZ)”
我正在使用 Visual Studio 2010。我知道这意味着它无法在任何源文件中找到函数定义。但是我已经在与调用它的文件位于同一目录中的文件中定义了它们。也许 Visual Studio 不会在当前目录中查找,除非您设置了一些链接器选项?
这里是源代码:
//HashTable.h
#ifndef HASH_H
#define HASH_H
class HashTable {
public:
HashTable();
~HashTable();
void AddPair(char* address, int value);
//Self explanatory
int GetValue(char* address);
//Also self-explanatory. If the value doesn't exist it throws "No such address"
};
#endif
//HashTable.cpp
class HashTable {
protected:
int HighValue;
char** AddressTable;
int* Table;
public:
HashTable(){
HighValue = 0;
}
~HashTable(){
delete AddressTable;
delete Table;
}
void AddPair(char* address, int value){
AddressTable[HighValue] = address;
Table[HighValue] = value;
HighValue += 1;
}
int GetValue(char* address){
for (int i = 0; i<HighValue; i++){
if (AddressTable[HighValue] == address) {
return Table[HighValue];
}
}
//If the value doesn't exist throw an exception to the calling program
throw 1;
};
};
【问题讨论】:
标签: c++ visual-studio-2010 linker