I am trying to return the address of an array @element from my Hash Table using the find function. However, I am getting the compiler error:
QuadraticProbing.cpp:134:59: error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]
return isActive( currentPos ) ? wordElement : ITEM_NOT_FOUND;
Basically, I just want to return a pointer to @element. So I tried creating a pointer wordElement to @element and tried returning wordElement. But that didn't work. Here is a snippet of my code, I can't figure out how to get a pointer to @element in HashEntry.
//Main
int main()
{
QuadraticHashTable<char*> table(100);
table.insert("HELLO WORLD");
if (table.find(document[i]) == NULL))
cout << "OH NO!";
}
//Class that has element that I want to return in find.
template <class HashedObj>
class QuadraticHashTable
{
public:
QuadraticHashTable()
const HashedObj & find( const HashedObj & x ) const;
enum EntryType { ACTIVE, EMPTY, DELETED };
private:
struct HashEntry
{
char element[20];
EntryType info;
HashEntry( const HashedObj & e = HashedObj( ), EntryType i = EMPTY )
: info( i )
{
if (e != NULL)
strcpy(element, e);
}
};
vector<HashEntry> array;
//Find Function
template <class HashedObj>
const HashedObj & QuadraticHashTable<HashedObj>::find( const HashedObj & x ) const
{
int currentPos = findPos( x );
const char * wordElement = array[currentPos].element;
return isActive( currentPos ) ? wordElement : ITEM_NOT_FOUND;
}
array[currentPos].elementis achararray. The function tries to return aHashedObj &. This cannot work. And why are you designing in a special "not-a-value" value? Do you know what the billion dollar mistake is?