我在xcode中有一個程序,並且只有骨架運行正常。我添加了一些代碼,當我添加了三個函數時,都是私有的,其中兩個函數內聯到.h和.cpp。當我去編譯時,我得到了鏈接器錯誤,因爲上帝知道什麼原因。我在做函數的類也從一個結構繼承,但我不認爲這應該是一個問題。我張貼下面的代碼。 (有很多對這個項目,所以我不能完成發佈)XCode鏈接器錯誤,簡單的C++函數
#ifndef HEAP_SORT_H
#define HEAP_SORT_H
#include "Interfaces02.h"
#include "CountedInteger.h"
class HeapSort : public IHeapSort {
public:
HeapSort();
virtual ~HeapSort();
virtual void buildHeap(std::vector<CountedInteger>& vector);
virtual void sortHeap(std::vector<CountedInteger>& vector);
private:
virtual unsigned int l(int i);
virtual unsigned int r(int i);
virtual void fixDown(std::vector<CountedInteger>& vector, int p);
};
#endif
#include "HeapSort.h"
#include "CountedInteger.h"
HeapSort::HeapSort()
{
}
HeapSort::~HeapSort()
{
}
void HeapSort::buildHeap(std::vector<CountedInteger>& vector)
{
int i = ((int) vector.size()) - 1;
for(; i > 1; i--)
{
fixDown(vector, i);
}
}
void HeapSort::sortHeap(std::vector<CountedInteger>& vector)
{
}
inline unsigned int l(int i)
{
return ((i*2)+1);
}
inline unsigned int r(int i)
{
return ((i*2)+2);
}
void fixDown(std::vector<CountedInteger>& vector, int p)
{
int largest;
if(l(p) <= vector.size() && vector[l(p)] > vector[p])
{
largest = l(p);
}
else
{
largest = p;
}
if(r(p) <= vector.size() && vector[r(p)] > vector[p])
{
largest = r(p);
}
if(largest != p)
{
CountedInteger temp = vector[largest];
vector[largest] = vector[p];
vector[p] = temp;
fixDown(vector, largest);
}
}
,這裏是它給我的錯誤:
Undefined symbols for architecture x86_64:
"HeapSort::l(int)", referenced from:
vtable for HeapSort in HeapSort.o
"HeapSort::r(int)", referenced from:
vtable for HeapSort in HeapSort.o
"HeapSort::fixDown(std::vector<CountedInteger,std::allocator<CountedInteger>>&,int)",
referenced from:
vtable for HeapSort in HeapSort.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
您尚未發佈錯誤。 – 2012-03-05 21:06:46
對不起,忘了剛發佈他們 – Dreken105 2012-03-05 21:07:26
沒關係,發現錯誤無論:P – 2012-03-05 21:09:16