出现
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
时间: 2024-10-18 03:35:59