Xcode未定义的符号〜析构函数

时间:2016-09-19 17:27:40

标签: c++ xcode

Undefined symbols for architecture x86_64:
  "Matrix::~Matrix()", referenced from:
      _main in p1.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

尝试在xcode中编译时出现此错误。问题在于头文件中的析构函数声明。如果我将析构函数注释掉,它就会成功构建。

class Matrix {
public:
    ~Matrix();     
}; 

1 个答案:

答案 0 :(得分:0)

您尚未定义析构函数。当你注释掉它时,析构函数将是一个隐式声明的析构函数,因此链接器会找到它。你声明“......将被定义”。这是否意味着你还没有定义它?

来自cppreference.com(http://en.cppreference.com/w/cpp/language/destructor

  

如果没有为类类型提供用户声明的析构函数(struct,   class或union),编译器总是将析构函数声明为   同类的内联公共成员。