這是一種複雜的問題。使用cstring類型的模板作爲非模板類的數據成員
class Stats {
public:
Stats();
// some functions
QuadraticHashTable<char[4]> teamHash;
};
由於要求,我必須使用模板QuadraticHashTable來器C風格字符串,我必須定義在類統計一QuadraticHashTable類型的數據成員,這是不是一個模板。
任何人都可以告訴我我的聲明有什麼問題嗎?編譯器不斷告訴我,
「呼叫沒有匹配功能‘QuadraticHashTable :: QuadraticHashTable()’ 」
順便說一句,我還沒有初始化的數據成員在構造函數統計
謝謝您。對於QuadraticHashTable
template <class HashedObj>
class QuadraticHashTable
{
public:
explicit QuadraticHashTable(const HashedObj & notFound, int size = 101);
QuadraticHashTable(const QuadraticHashTable & rhs)
: array(rhs.array), ITEM_NOT_FOUND(rhs.ITEM_NOT_FOUND),
currentSize(rhs.currentSize) { }
const HashedObj & find(const HashedObj & x) const;
void makeEmpty();
void insert(const HashedObj & x);
void remove(const HashedObj & x);
const QuadraticHashTable & operator=(const QuadraticHashTable & rhs);
enum EntryType { ACTIVE, EMPTY, DELETED };
/////////////////////////////////////////////////////
friend class Stats;
/////////////////////////////////////////////////////
private:
struct HashEntry
{
HashedObj element;
EntryType info;
HashEntry(const HashedObj & e = HashedObj(), EntryType i = EMPTY)
: element(e), info(i) { }
};
vector<HashEntry> array;
int currentSize;
const HashedObj ITEM_NOT_FOUND;
bool isPrime(int n) const;
int nextPrime(int n) const;
bool isActive(int currentPos) const;
int findPos(const HashedObj & x) const;
int hash(const string & key, int tableSize) const;
int hash(int key, int tableSize) const;
void rehash();
};
我們需要'QuadraticHashTable'的頭文件代碼來幫助你。 –
我不認爲它有問題,因爲它是由教授提供的模板代碼 – Bruce
該類是否具有默認構造函數 – rerun