我將函數轉換爲模板,並開始出現此錯誤。我不能理解模板的限制。有人能告訴我爲什麼這是壞的?當我鏈接下面的代碼使用模板鏈接錯誤
Undefined symbols:
"bool foo<int>(int const&, int const&)", referenced from:
_main in file1.o
ld: symbol(s) not found
:
我收到此錯誤。代碼被簡化了,但仍然失敗。第一個文件包含:
#include <iostream>
template <class T> bool foo (const T&, const T&);
int main()
{
int left = 1;
int right = 2;
if (foo <int> (left, right))
std::cout << "foo!" << std::endl;
return 0;
}
而第二個文件包含:
template <class T> bool foo (const T& left, const T& right)
{
return true;
}
static/inline mods沒有任何作用。我很難過。 – 2009-02-15 03:03:59