c++ - Undefined reference to header file function -
i got error of c:\temp\hashtableproject\main.cpp|14|
undefined reference hash::hash(std::string)
know how solve 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 main.o file in obj folder. dont know why hash.o isn't there.
hash inbuilt template in "std" namespace.
try removing using namespace std; lien , use namespace name , when required.
Comments
Post a Comment