이 코드가 컴파일되지 않는 이유를 이해해 주시겠습니까? C++ 템플릿을 이해하려고합니다.함수 템플릿
#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;
}
컴파일되지 않으면 적어도 오류를 제공하십시오. – chris
또한 "using namespace std;"를 포함 할 수도 있습니다. 그래서 당신은 "std ::" – jrubins
@jrubins을 쓰는 것을 계속 할 필요가 없다. 그것은 일반적으로 [나쁜 연습]으로 간주된다. (http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered- a-bad-practice-in-c). – chris