Code:
[C++ Error] hash.h(148): E2015 Ambiguity between 'hash::Hashtable<_STL::basic_string<char,_STL::char_traits<char>,_STL::allocator<char> >,_STL::basic_string<char,_STL::char_traits<char>,_STL::allocator<char> > >::hashValue(_STL::basic_string<char,_STL::char_traits<char>,_STL::allocator<char> >)' and 'hash::Hashtable<_STL::basic_string<char,_STL::char_traits<char>,_STL::allocator<char> >,_STL::basic_string<char,_STL::char_traits<char>,_STL::allocator<char> > >::hashValue(_STL::basic_string<char,_STL::char_traits<char>,_STL::allocator<char> >)'
[C++ Error] hash.h(159): E2015 Ambiguity between 'hash::Hashtable<_STL::basic_string<char,_STL::char_traits<char>,_STL::allocator<char> >,_STL::basic_string<char,_STL::char_traits<char>,_STL::allocator<char> > >::hashValue(_STL::basic_string<char,_STL::char_traits<char>,_STL::allocator<char> >)' and 'hash::Hashtable<_STL::basic_string<char,_STL::char_traits<char>,_STL::allocator<char> >,_STL::basic_string<char,_STL::char_traits<char>,_STL::allocator<char> > >::hashValue(_STL::basic_string<char,_STL::char_traits<char>,_STL::allocator<char> >)'
[C++ Error] hash.h(161): E2015 Ambiguity between '_STL::basic_string<char,_STL::char_traits<char>,_STL::allocator<char> >::operator =(const char *)' and '_STL::basic_string<char,_STL::char_traits<char>,_STL::allocator<char> >::operator =(char)'
// this is my code
// header file hash.h
// Define la libreria
#ifndef _HASH_H
#define _HASH_H
// Incluye definicion de null
#include<stddef>
#include<cstring>
#include<bitset>
// Tamanyo default y fijo
#define TABLE_SIZE 10240
using namespace std;
namespace hash
{
template <class Key, class T>
class Hashtable
{
// Miembros publicos
public:
// Definicion de tipos
typedef typename T value_type;
typedef typename Key key_type;
// Miembros protegidos
protected:
// numero de items
size_t numItems;
// Definicion de la tabla
value_type table[TABLE_SIZE];
private:
//Calcula la posicion cuando...
// La llave es unsigned
inline unsigned hashValue(unsigned key)
{
return (31*key)%TABLE_SIZE;
}
// La llave es int
inline unsigned hashValue(int key)
{
return (31*key)%TABLE_SIZE;
}
// La llave es long
inline unsigned hashValue(unsigned long key)
{
return hashValue( reinterpret_cast<unsigned>(key) );
}
// La llave es long
inline unsigned hashValue(long key)
{
return hashValue( reinterpret_cast<int>(key) );
}
// La llave es float
inline unsigned hashValue(float key)
{
// Convierte a bits el numero de punto flotante
unsigned *keyRef = reinterpret_cast<unsigned*>(&key);
bitset<32> bits(*keyRef);
// convierte los bits a un unsigned long;
return hashValue( bits.to_ulong() );
}
// La llave es double
inline unsigned hashValue(double key)
{
// Convierte a bits el numero de punto flotante
unsigned *keyRef = reinterpret_cast<unsigned*>(&key);
bitset<32> lsBits(*keyRef); // 32 bits menos significativos
bitset<32> msBits(*(++keyRef)); // 32 bits mas significativos
// Manipulacion para generar la llave
lsBits ^= msBits;
return hashValue( lsBits.to_ulong() );
}
// La llave es string
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%TABLE_SIZE;
}
// La llave es char
inline unsigned hashValue(char key)
{
return hashValue( reinterpret_cast<int>(key) );
}
// La llave es unsigned char
inline unsigned hashValue(unsigned char key)
{
return hashValue( reinterpret_cast<unsigned>(key) );
}
// La llave es de otro tipo
inline unsigned hashValue(key_type key)
{
return hashValue( reinterpret_cast<unsigned>(&key) );
}
// Miembros publicos
public:
// Constructor
explicit Hashtable()
{
// Inicializa el numero de items
this->numItems = 0;
}
Hashtable(const Hashtable<Key, T>& t)
{
// Inicializa el numero de items
this->numItems = t.numItems;
// Copia la memoria
for(int index=0; index<TABLE_SIZE; index++)
this->table[index] = t.table[index];
}
// Verifica si la tabla hash contiene la llave
bool containsKey(key_type key)
{
// Ubica la posicion y contenido
unsigned index = hashValue(key);
value_type val = table[index];
if(val) return true;
return false;
}
// Agrega un elemento a la tabla hash
value_type put(key_type key, value_type value)
{
// Ubica la posicion y contenido
unsigned index = hashValue(key);
value_type val = table[index];
table[index] = value;
return val;
}
// Obtiene un elemento a la tabla hash
value_type get(key_type key)
{
// Ubica la posicion y contenido
unsigned index = hashValue(key);
value_type val = table[index];
table[index] = NULL;
return val;
}
};
}
#undef TABLE_SIZE
#endif
// test.cpp
#include<iostream>
#include<cstring>
#include"hash.h"
using namespace std;
using namespace hash;
Hashtable<string, string> h;
string guitarristas[10]={ "Steve Vai", "Joe Satriani",
"Dave Mustaine", "Troy Stetina", "Zakk Wylde",
"Jimmy Hendrix", "Luca Turilli", "Yngwie Malmsteen",
"Al DiMeola", "Adrian Smith"};
void main()
{
for(int index=0; index<10; index++)
h.put(guitarristas[index],guitarristas[index]);
for(int index=0; index<10; index++)
h.get(guitarristas[index]);
}