我正在尝试使用Atom设置cpp项目。我的项目(下图)。我的代码(下面的代码片段)。我得到错误
undefined reference to hashCustom::Hash(std::__cxx11::basic_string, std::allocator >)
collect2: error: ld returned 1 exit status
. 我从教程中做了所有的事情,有一点不同,那个教程使用Visual Studio,但它不支持Linux。如何消除错误?
hash.h
#include <iostream>
#include <string>
using namespace std;
#ifndef HASH_H
#define HASH_H
class hashCustom {
public:
int Hash(string key);
};
#endif
hash.cpp
#include <iostream>
#include <string>
#include "../Header Files/hash.h"
using namespace std;
int hashCustom::Hash(string key) {
int index;
index = key.length();
return index;
}
main.cpp
#include <iostream>
#include <string>
#include "../Header Files/hash.h"
using namespace std;
int main() {
hashCustom hashObj;
cout << hashObj.Hash("Number") << endl;
return 0;
}