I'm newbie in C++ programming and I want to declare a constructor from following code in my main however I'm completely confused about it. Here is the code:

#include <vector>
using namespace std;

template <typename HashedObj>
class HashTable
{
    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 );

    enum EntryType { ACTIVE, EMPTY, DELETED };

    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 isActive( int currentPos ) const;
    int findPos( const HashedObj & x ) const;
    void rehash( );
};

Thanks.

That's kind of an awkward design. Let's say you're hashing integers, you could do something like this (assuming the class works like I think it does):

HashTable<int> ht(-1);

It says that the hash table will use -1 as the "item not found" marker value. The idea is that the argument represents a suitable sentinel value for searched items that aren't in the table.

This article has been dead for over six months. Start a new discussion instead.