Я получил ошибку C:\temp\hashTableProject\main.cpp|14|
undefined ссылка на hash::Hash(std::string)
Кто-нибудь знает, как решить эту проблему?
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 с использованием CodeBlock 13.12 В папке obj есть только файл main.o. Я не знаю, почему hash.o там нет.
hash - встроенный шаблон в пространстве имен std.
Попробуйте удалить с помощью пространства имен std; залоговое право и использовать имя пространства имен по мере необходимости.
hash.cpp
в ваш проект блоков кода.