I was experimenting to find how arguments are deduced when we use templates in c++, I came though a case which was strange for me.
As per my understanding template parameters should be present in call parameters. But in the code below, I tried to skip the first template parameter and the code compiles and runs fine. I think I have gaps in my understanding.
This is just an experimental code:
#include <iostream>
#include <cstring>
#include <string>
#include <typeinfo>
using namespace std;
template <typename T, typename T1>
T1 const& max (T1 const & a, T1 const & b) //"typename T" is not present here
{
cout<<"inside func max a: "<<typeid(a).name()<<endl;
cout<<"inside func max b: "<<typeid(b).name()<<endl;
return a < b ? b : a;
}
int main ()
{
::max<double>(7, 42);
cout<<typeid(::max<double>(7, 42)).name();
}
This code runs fine, no errors. But how it managed to skip typename T parameter. Can somebody please explain or provide some link on this.