In the Infinite Skills "Advanced C++ Programming Training Video", in a section about function templates, the presenter said that while passing the arguments to such function, we need to pass them by references and not by values as it might result in compiler giving us a "hard time". I have no idea about what this could be. The function calculates the maximum value of the two arguments and returns the same. The two functions are as follows:
// The function given in the tutorial
T maxVal(T &a1, T &a2)
{
if(a1<a2)
return a1;
else
return a2;
}
// My function
T maxVal(T a1, T a2)
{
if(a1<a2)
return a1;
else
return a2;
}
The problem is that both of the seem to work fine. Could you please help me by telling what are possible "hard times" that I can get ?