HashTable error: multiple definition of 'HashTableSavitch::HashTable::HashTable()'

Hi cplusplus.com forum people,
I've typed up this code direct from the text book, Absolute C++ Fourth Edition Savitch ISBN-13: 978-0-13-136584-1.
Learning how to make a HashTable.
hashtable.cpp on page 803 gives the error on line 12:
Line 12: multiple definition of 'HashTableSavitch::HashTable::HashTable()'
Line 12: first defined here
Line 12: In function 'HashTable':

Could someone help as I'm learning and this is pushing me over my learning curve :-(
closed account (o3hC5Di1)
Hi there,

Could you please post your code so we can see what it is that's breaking it?

Not all of us have the book you mention (well I don't anyway), so being able to view the code would help us help you :)

All the best,

NwN
Sorry, only my 2nd post. Here 'tis.
I bolded Line 12 where the error occurs.

hashtable.cpp

//This is the implementation file hashtable.cpp.
//This is the implementation of the class HashTable.
#include <string>
#include "listtools.h"
#include "hashtable.h"
using LinkedListSavitch::Node;
using LinkedListSavitch::search;
using LinkedListSavitch::headInsert;
using std::string;
namespace HashTableSavitch
{
HashTable::HashTable()
{
for (int i = 0; i < SIZE; i++)
{
hashArray[i] = NULL;
}
}
HashTable::~HashTable()
{
for (int i = 0; i < SIZE; i++)
{
Node<string> *next = hashArray[i];
while (next != NULL)
{
Node<string> *discard = next;
next = next->getLink();
delete discard;
}
}
}
int HashTable::computeHash(string s)
{
int hash = 0;
for (int i = 0; i < s.length(); i++)
{
hash = hash + s[i];
}
return hash % SIZE;
}
void HashTable::put(string s)
{
int hash = computeHash(s);
if (search(hashArray[hash], s)==NULL)
{
//Only add the target if it's not in the list.
headInsert(hashArray[hash], s);
}
}
}
//HashTableSavitch

Topic archived. No new replies allowed.