HELP PLEASE: I can't find the error
Hello everyone, how do you do?
I do not know where is the error in this code, I am currently working with C++ Builder 6.
C++ Builder marks an error where in the bold letters, this is the following error:
[C++ Error] test.cpp(16): E2139 Declaration missing ;
I do not know what to do :confused: !!!
Help please!!!
Regards Reivaj.
Code:
#include<math>
#include<stddef>
#include<memory>
#include<cstring>
#include<bitset>
#define TABLE_SIZE 128
#define Allocator allocator
template <class Key, class T>
class Hashtable
{
public:
typedef Allocator<T> hashtable_allocator;
typedef typename hashtable_allocator::reference reference;
typedef typename hashtable_allocator::const_reference const_reference;
typedef typename hashtable_allocator::pointer iterator;
typedef typename hashtable_allocator::const_pointer const_iterator;
typedef typename hashtable_allocator::size_type size_type;
typedef typename hashtable_allocator::difference_type difference_type;
typedef typename T value_type;
typedef typename Key key_type;
protected:
float loadFactor;
size_t size, numItems, thresold;
Allocator<T> the_allocator;
iterator start, finish, end_of_storage;
inline unsigned hashValue(unsigned key)
{
return (31*key)%size;
}
inline unsigned hashValue(unsigned long key)
{
return hashValue( reinterpret_cast<unsigned>(key) );
}
inline unsigned hashValue(float key)
{
unsigned *keyRef = reinterpret_cast<unsigned*>(&key);
bitset<32> bits(*keyRef);
return hashValue( bits.to_ulong() );
}
inline unsigned hashValue(double key)
{
unsigned *keyRef = reinterpret_cast<unsigned*>(&key);
bitset<32> lsBits(*keyRef);
bitset<32> msBits(*(++keyRef));
lsBits ^= msBits;
return hashValue( lsBits.to_ulong() );
}
inline unsigned hashValue(string key)
{
unsigned h=0;
size_t len = key.length();
for(unsigned i=0; i<len; i++)
h = 31*h + key[i];
return h%size;
}
inline unsigned hashValue(key_type key)
{
return hashValue( reinterpret_cast<unsigned>(&key) );
}
public:
explicit Hashtable(size_t size, float loadFactor)
{
this->size = size > 0 ? size:TABLE_SIZE;
this->loadFactor = loadFactor;
this->thresold = this->size * this->loadFactor;
this->numItems = 0;
start = the_allocator.allocate(this->size);
T value;
uninitialized_fill_n(start, this->size, value);
finish = start + this->size;
end_of_storage = finish;
}
explicit Hashtable(size_t size)
{
this( size, 0.75 );
}
Hashtable(const Hashtable<T>& t)
{
this->size = t.size;
this->loadFactor = t.loadFactor;
this->thresold = t.thresold;
this->numItems = t.numItems;
this->start = this->the_allocator.allocate(t.finish - t.start);
uninitialized_copy(t.start, t.finish, this->start);
this->end_of_storage = this->finish;
}
~Hashtable()
{
destroy(start, finish);
the_allocator.deallocate(start);
}
iterator begin(){ return start; }
const_iterator begin() const { return start; }
iterator end(){ return finish; }
const_iterator end() const { return finish; }
}