Reputation: 2875
I got an error of C:\temp\hashTableProject\main.cpp|14|
undefined reference to hash::Hash(std::string)
Anyone know how to solve this problem?
hash.h
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
#ifndef HASH_H
#define HASH_H
class hash{
public:
int Hash(string key);
};
#endif // HASH_H
hash.cpp
#include <iostream>
#include <cstdlib>
#include <string>
#include "hash.h"
using namespace std;
int hash::Hash(string key){
//int hash = 0;
int index;
index = key.length();
return index;
}
main.cpp
#include <iostream>
#include <cstdlib>
#include <string>
#include "hash.h"
using namespace std;
int main()
{
int index;
hash hashOb;
string traget = "Testing";
index = hashOb.Hash(traget);
cout << index << endl;
return 0;
}
Im using CodeBlock 13.12 There is only main.o file in obj folder. I dont know why the hash.o isn't there.
Upvotes: 0
Views: 1201
Reputation: 1856
hash is an inbuilt template in "std" namespace.
Try removing using namespace std; lien and use namespace name as and when required.
Upvotes: 1