fant_lampe
Grünschnabel
Hashtable - Anfänger braucht Hilfe
Hallo! Ich versuche mir gerade eine kleine Hashtabelle zu erstellen, nutzlos, aber ich will ja lernen.
Sie funktioniert nicht. Weiß jemand woran das liegt? Vielen Dank!
hash.h:
hash.cpp:
main.cpp:
Hallo! Ich versuche mir gerade eine kleine Hashtabelle zu erstellen, nutzlos, aber ich will ja lernen.
Sie funktioniert nicht. Weiß jemand woran das liegt? Vielen Dank!
hash.h:
Code:
#include<cstdlib>
#include <iostream>
#include <string>
using namespace std;
#ifndef Hash_H
#define HASH_H
class hash{
public:
int Hash (string key); // grober Index für Array
};
#endif
hash.cpp:
Code:
#include<cstdlib>
#include <iostream>
#include <string>
#include "hash.h"
using namespace std;
int hash::Hash (string key) // Laut Compiler fehlt hier der Funktionsheader
{
int hash = 0;
int index;
index = key.length();
cout<< "key[0] = "<<key[0] <<endl;
cout<< "key[1] = "<<key[1] <<endl;
cout<< "key[2] = "<<key[2] <<endl;
cout<< "key[3] = "<<key[3] <<endl;
cout<< "key[4] = "<<key[4] <<endl;
return index;
}
main.cpp:
Code:
#include<cstdlib>
#include <iostream>
#include <string>
#include "hash.h"
using namespace std;
int main (int argc, char**argv)
{
int index;
hash hashObj; //laut Fehlermeldung ist "hash" mehrdeutig, aber warum?
index = hashObj.Hash("Steff");
cout<< "index = " <<index<<endl;
getchar();
getchar();
return 0;
}
Zuletzt bearbeitet: