I’m referencing a templated quicksort method in my cpp function like this:
Main.cpp
QuickSort<vector<int>>(testData);
Where testData is:
int arr[] = {0, 5, 3, 4, 2, 1, 4};
vector<int> testData (arr, arr + sizeof(arr) / sizeof(arr[0]));
The declaration of quicksort in the .h file is:
Sorting.h
template <typename T>
void QuickSort(std::vector<T>& Unsorted);
And the function definition is:
Sorting.cpp
template <typename T>
void QuickSort(std::vector<T>& Unsorted)
{
//implementation here
}
Am I losing my mind? I’m just trying to pass a vector of ints by reference. Could someone tell me where I’m going wrong?
templates cannot have separate definition and declaration
also
in case of functions declaration and definition must be in the saem place, ie:
wont compile, when
compiles just fine, check in stl how template functions are made.
The thing is, that compiler must know entire function before its usage, and he doesnt in your case