出現
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
