首页 > 代码库 > C++ 常见的 Undefined symbols for architecture *

C++ 常见的 Undefined symbols for architecture *

出现 

Undefined symbols for architecture x86_64:

的原因

1.函数申明了,却未被定义。

2.申明的虚函数未被实现。

NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.

3.使用template <class T> 实现类时。若是将函数声明写在.h文件,实现写在.cpp。则出现Undefined symbols for architecture x86_64。应将申明和实现都放在.h文件

template <class T>
class Heap {
    typedef typename vector<T>::iterator iterator;
private:
    vector<T> container;
    void swim(int i);
    void sink(int i);
};
template <class T>
void Heap<T>::swim(int i) {
    while (i > 1&&container[i]>container[i/2])
    {
        T temp = container[i];
        container[i] = container[i/2];
        container[i/2] = temp;
        i = i/2;
    }
}

 http://www.cnblogs.com/like1/p/6848669.html

C++ 常见的 Undefined symbols for architecture *