Automatic Type Deduction with the auto Keyword
Learn about the automatic type deduction and use the auto keyword when declaring functions and variables.
We'll cover the following
Since the introduction of the auto
keyword in C++11, there has been a lot of confusion in the C++ community about how to use the different flavors of auto
, such as const auto&
, auto&
, auto&&
, and decltype(auto)
.
Using auto
in function signatures
Although discouraged by some C++ programmers, in our experience the use of auto
in function signatures can increase readability when browsing and viewing header files.
Here is how the auto
the syntax looks compared to the traditional syntax with explicit types:
Get hands-on with 1200+ tech skills courses.