In the 4th edition of Bjarne Stroustrup book (The C++ programing language) we read that:
Using auto , we avoid redundancy and writing long type names. This is especially important in generic programming where the exact type of an object can be hard for the programmer to know and the type names can be quite long (§4.5.1).
So, to understand the importance of this type. I made this small test program:
#include <iostream>
/*-----------------------------*/
auto multiplication(auto a, auto b)
{
return a * b;
}
int main()
{
auto c = multiplication(5,.134);
auto d = 5 * .134;
std::cout<<c<<"\n"<<d<<"\n";
}
The stdout of this program (compiled with -std=C++14):
0
0.67
I am wondering why I got different results (types) with c and d variables even if the return type of multiplication function is auto.
EDIT:
My GCC version: gcc version 5.4.0 20160609