#include <iostream>
using std::cout;
using std::endl;
#include <string>
using std::string;
template <class T>
T max(T const& t1, T const& t2) {
return t1 < t2 ? t2 : t1;
}
int main() {
cout << max(1, 2) << endl;
cout << max<double>(1.2, 2) << endl;
string s1 = "hello";
string s2 = "world";
--> cout << max(s1, s1) << endl;
}
On the line with arrow, it complains about: "more than one instance of function template "max" matches the argument list: -- function template "const _Tp &std::__1::max(const _Tp &__a, const _Tp &__b)"-- function template "T max(const T &t1, const T &t2)" -- argument types are: (std::__1::string, std::__1::string)"
I am confused since both of them are string, and not sure what else the template can match of.