错误:使用C ++时未定义的符号错误

时间:2016-02-06 22:50:34

标签: c++ class

我写了一个非常简单的程序,包含3个文件:

hash.cpp

#include <iostream>
#include <string>
#include "hash.h"
using namespace std;

void hashclass::test(){
 cout << "Inside the hashclass function def" << endl;
 cout << "Hello!" << endl; }

hash.h

#include <iostream> 
#include <string>
using namespace std;
#ifndef HASH_H 
#define HASH_H

class hashclass{
public:
void test();
};

#endif

的main.cpp

#include <iostream>
#include <string>
#include "hash.h"
#include <cstdlib>
using namespace std;

int main(int argc, char **argv){

  hashclass hashObj;
  hashObj.test();
  return 0;}

使用g ++编译时,我收到以下错误:

Undefined symbols for architecture x86_64:

"hashclass::test()", referenced from: _main in main-9f5786.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我尝试了很多来弄清楚出了什么问题,我没有看到上面的代码存在任何问题。

0 个答案:

没有答案