ヘッダークラスを持ついくつかのファイルに単純なハッシュテーブルクラスを含めることを試みています。コンパイルしようとすると次のようないくつかのエラーが発生します:Visual C++リンカーエラー2019
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++でクラスを作成する方法(http://www.learn-programming.za.net/programming_cpp_learn10.html) –