我将函数转换为模板,并开始出现此错误。我不能理解模板的限制。有人能告诉我为什么这是坏的?当我链接下面的代码使用模板链接错误
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