Warum schlägt die Iterator-Typ-Ableitung fehl? [Duplikat]
Diese Frage hat hier bereits eine Antwort:
Warum kann das Template-Argument nicht abgeleitet werden, wenn es als Template-Parameter für ein anderes Template verwendet wird? 4 AntwortenWarum funktioniert das in C ++ nicht?
Warum kann ich nicht einschränkenfoo
's Parameter aufstd::vector<T>::iterator
wie folgt und was ist die beste Problemumgehung?
#include <vector>
template<class T>
void foo(typename std::vector<T>::iterator) { }
int main()
{
std::vector<int> v;
foo(v.end());
}
Der Fehler ist:
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’