I wrote a hash table class and header but I cannot construct it on main. It gives “no appropriate default constructor available”. What is the cause of that?
Constructor in my header: HashTable.h
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 ) { }
Constructor in my cpp: HashTable.cpp
HashTable<HashedObj>::HashTable( const HashedObj & notFound, int size )
: ITEM_NOT_FOUND( notFound ), array( nextPrime( size ) )
{
makeEmpty( );
}
And I’m trying to do following code in my main:
HashTable <int> * hash = new HashTable<int>();
You’ve defined a constructor which takes argument, but here you’re not passing arguments to the constructor. Instead you’re using a parameterless (default) constructor which doesn’t exist in your class.
Note that if you’ve defined a constructor (which takes argument(s)) in your class, then the compiler will not generate a default constructor for you. You’ve to define it yourself.