template<typename T1, typename T2>
void printPair(const std::pair<T1, T2> &p) {
std::cout << p.first << ", " << p.second << std::endl;
}
int main() {
printPair({1, 1});
return 0;
}
When I try to compile that code, the compiler is unable to infer the template arguments to the function printPair
. If I remove the template code and change the parameter to std::pair<int,int>
then the code compiles fine. Or I can keep the template and change the call to printPair(std::make_pair(1, 1))
and it also works fine.
Why can't the template arguments be deduced without using make_pair
?