I am trying to implement a Template function of the Manhattan Distance for vectors that have any type (int, float etc) of coordinates, in C++.
So I have this:
template <typename T>
T manhattan_distance(std::vector<T> v1, std::vector<T> v2) {
//implementation
}
When trying to use it (in another file), I do as follows:
std::vector<int> v1 = [1,2,3];
std::vector<int> v2 = [4,5,5];
int res = manhattan_distance(v1,v2);
When make
-ing, I get this error:
undefined reference to `int manhattan_distance<int>(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
What is the issue? The function is not in a class. Am I missing something? Thanks in advance!