0

テンプレートを使用して HashTable クラスを作成しています。ただし、文字列や数値データ型 (さらには整数のみ) を処理するときに、テンプレートの性質を維持する方法を見つけることができないようです。これは、HashKey が文字列型である限り機能するコードです。

template<typename HashKey>
size_t HashTable<HashKey>::myhash(const HashKey & x) const
{
    unsigned int hashVal = 0;
    for (unsigned int i = 0; i < x; i++)
    hashVal = (hashVal << 5) ^ x[i] ^ hashVal;
    return hashVal % hashTable.size();
};

次のようなものを使用して動作させる方法はありますか

unsigned int hashVal = 0;
hashVal = (hashVal << 5) ^ x ^ hashVal;
return hashVal % hashTable.size();

ここで何か助けはありますか?

4

0 に答える 0