I'm new to C++. This is for my homework and below is the code that was given to us by the professor to help us work on this assignment but it doesn't compile... I've marked the line where error is generated and the error message is
"Cannot refer to template 'hash' without a template argument list".
I'm not sure how to fix it. Can someone point me to the right direction, please?
(I've removed the lines that, I assume, is irrelevant to the error message.)
The class is defined as:
template <typename HashedObj>
class HashTable
{
public:
//....
private:
struct HashEntry
{
HashedObj element;
EntryType info;
HashEntry( const HashedObj & e = HashedObj( ), EntryType i = EMPTY )
: element( e ), info( i ) { }
};
vector<HashEntry> array;
int currentSize;
//... some private member functions....
int myhash( const HashedObj & x ) const
{
int hashVal = hash( x ); <<--- line with error
hashVal %= array.size( );
if( hashVal < 0 )
hashVal += array.size( );
return hashVal;
}
};
int hash( const HashedObj & key );
int hash( int key );
--- and int hash() function in cpp file ----
int hash( const string & key )
{
int hashVal = 0;
for( int i = 0; i < key.length( ); i++ )
hashVal = 37 * hashVal + key[ i ];
return hashVal;
}
int hash( int key )
{
return key;
}