我想在包含頭類的某些文件中包含一個簡單的哈希表類。但是每當我嘗試編譯時,我會得到如下幾個錯誤:Visual C++鏈接器錯誤2019
LNK2019:無法解析的外部符號「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++類(http://www.learn-programming.za.net/programming_cpp_learn10.html) – 2012-03-28 21:03:07