This question is only applicable until C++11. The C++14 standard allows auto
return type for regular functions.
[References]
Read this for explanation
C++11 introduced keyword auto that can be used as a placeholder for data types. auto instructs compiler to deduce the actual type of variable from expression. e.g
auto x = 5; // x is inferred as int
auto pFoo = new Foo(); // and pFoo as Foo*
However auto cannot be used as return type of a function. Following code will not compile:
template<typename T1, typename T2>
auto mult(T1 a, T2 b ) // Compilation Error
{
return a*b;
}
Suppose we want to have a generic implementation of mult, considering above which one of the following is best solution?