#include <iostream>
#include <vector>
#include <map>
#include <string>
usingnamespace std;
template <typename T, typename U> map<T, T> func1( U u ) {
T t = u[0];
map<T, T> m;
m[t] = t;
return m;
}
int main() {
vector<int> vect;
vect.push_back(1);
map<int, int> m = func1(vect);
return 0;
}
and it does not compile. The error is:
test.cpp: In function ‘int main()’:
test.cpp:20:30: error: no matching function for call to ‘func1(std::vector<int>&)’
test.cpp:20:30: note: candidate is:
test.cpp:8:45: note: template<class T, class U> std::map<T, T> func1(U)
test.cpp:8:45: note: template argument deduction/substitution failed:
test.cpp:20:30: note: couldn't deduce template parameter ‘T’