This question already has an answer here:
I have a function that I put in a separate file with my other utility functions, with a separate header
The functions is a simple array sort:
template<class TYPE1>
void sorted_index(const TYPE1* arr, int n, int* indices)
{
int i, j;
for (i = 0; i < n; i++)
{
indices[i] = i;
}
for (i = 0; i<n; i++)
{
for (j = i + 1; j<n; j++)
{
if (arr[indices[i]] > arr[indices[j]])
{
//swap
int temp = indices[i];
indices[i] = indices[j];
indices[j] = temp;
}
}
}
}
And I use it like this somewhere else in another file:
myfloat testvar[6] = { 2.3, 2.1, 2.2, 5, -1, -2.5 };
int indices[6];
sorted_index(testvar, 6, indices);
I get this error:
error LNK2019: unresolved external symbol "void __cdecl sorted_index(double const *,int,int *)"
If I eliminate the template definition, it compiles, so I know there isn't a dependency issue.
Why am I getting that error? Thanks
Aucun commentaire:
Enregistrer un commentaire