왜 이것이 C++에서 작동하지 않습니까?
foo
의 매개 변수를 std::vector<T>::iterator
으로 제한 할 수없는 이유는 무엇이며 가장 좋은 해결 방법은 무엇입니까?왜 반복자 유형 공제가 실패합니까?
#include <vector>
template<class T>
void foo(typename std::vector<T>::iterator) { }
int main()
{
std::vector<int> v;
foo(v.end());
}
오류 :
In function ‘int main()’:
error: no matching function for call to ‘foo(std::vector<int>::iterator)’
note: candidate is:
note: template<class T> void foo(typename std::vector<T>::iterator)
note: template argument deduction/substitution failed:
note: couldn’t deduce template parameter ‘T’
템플릿 매개 변수를 추론 할 수없는 경우 일반적인 해결 방법이 있습니다. 명시 적으로 다음과 같이 지정하십시오.'foo (v.end());' –