I converted a function to a template, and started getting this error. I must not be understanding a limitation of templates. Can someone tell me why this is broken?
I am receiving this error:
Undefined symbols:
"bool foo<int>(int const&, int const&)", referenced from:
_main in file1.o
ld: symbol(s) not found
When I link the following code. The code is simplified, but still fails. The first file contains:
#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;
}
And the second file contains:
template <class T> bool foo (const T& left, const T& right)
{
return true;
}