我在代码中遇到此错误:
在私有函数的这一行中发现错误:
vector<HashEntry> array;
#ifndef _HASHTABLE_H
#define _HASHTABLE_H
#include <vector>
enum EntryType { ACTIVE, EMPTY, DELETED };
Template <class HashedObj>
struct HashEntry
{
HashedObj element;
EntryType info;
HashEntry( const HashedObj & e = HashedObj( ), EntryType i = EMPTY )
: element( e ), info( i ) { }
};
template <class HashedObj>
class HashTable
{
private:
vector<HashEntry> array;
int currentSize;
const HashedObj ITEM_NOT_FOUND;
bool isActive( int currentPos ) const;
int findPos( const HashedObj & x ) const;
public:
explicit HashTable( const HashedObj & notFound, int size = 101 );
HashTable( const HashTable & rhs )
: ITEM_NOT_FOUND( rhs.ITEM_NOT_FOUND ),
array( rhs.array ), currentSize( rhs.currentSize ) { }
const HashedObj & find( const HashedObj & x ) const;
void makeEmpty( );
void insert( const HashedObj & x );
void remove( const HashedObj & x );
const HashTable & operator=( const HashTable & rhs );
};
#endif
如何修复此错误C4430?
答案 0 :(得分:0)
HashEntry
本身是一个模板类,不会自动从包含HashTable
类推导出模板参数类型。您需要更改array
声明,如下所示
template <class HashedObj>
class HashTable {
private:
std::vector<HashEntry<HashedObj>> array;
// ^^^^^^^^^^^
// ...
};