can you please help me to understand why this code doesn't compile? I'm trying to understand C++ templates.
#include <iostream>
#include <algorithm>
#include <vector>
template <class myT>
void myfunction (myT i)
{
std::cout << ' ' << i;
}
int main ()
{
double array1[] = {1.0, 4.6, 3.5, 7.8};
std::vector<double> haystack(array1, array1 + 4);
std::sort(haystack.begin(), haystack.end());
std::cout << "myvector contains:";
for_each (haystack.begin(), haystack.end(), myfunction);
std::cout << '\n';
return 0;
}