Automatic Type Deduction: auto
The Facts of
Automatic type deduction with
auto is extremely convenient. Firstly, we save unnecessary typing, in particular with challenging template expressions. Secondly, the compiler does not make human errors.
The compiler automatically deduces the type from the initializer:
auto myDoub = 3.14;
- The techniques for automatic function template argument deductions are used.
- It is very helpful in complicated template expressions.
- It empowers us to work with unknown types.
- It must be used with care in combination with initializer lists.
The following code compares the definition of explicit and deduced types: