2012-03-28 14 views
0

ヘッダークラ​​スを持ついくつかのファイルに単純なハッシュテーブルクラスを含めることを試みています。コンパイルしようとすると次のようないくつかのエラーが発生します: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; 
    }; 

}; 
+0

[C++でクラスを作成する方法(http://www.learn-programming.za.net/programming_cpp_learn10.html) –

答えて

1

あなたはいません。新しいclassを作成しました。

メソッドを定義するための適切な方法がある:

//HashTable.cpp 

#include "HashTable.h" 
HashTable::HashTable(){ 
    HighValue = 0; 
} 
HashTable::~HashTable(){ 
    delete AddressTable; 
    delete Table; 
} 
void HashTable::AddPair(char* address, int value){ 
    AddressTable[HighValue] = address; 
    Table[HighValue] = value; 
    HighValue += 1; 
} 
int HashTable::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; 
}; 
+0

ああ。だから、関数を定義するとき、私はHashTable :: function()を使うべきですか? – user1296991

+0

@ user1296991。 –

+0

そして私はヘッダファイルにプライベート変数を含めるでしょうか? – user1296991

関連する問題