auto decltype and Type Deduction
Let the compiler deduce types with auto and decltype for cleaner code.
Type Deduction in Modern C++
Since C++11 the compiler can deduce types in many places. This makes code shorter and less error prone — when used wisely.
The auto Keyword
auto deduces the type from the initializer at compile time. The variable still has a fixed, statically-known type.
auto i = 42; // int
auto d = 3.14; // double
auto s = "hello"; // const char*
auto v = std::vector<int>{1,2,3}; // std::vector<int>All lessons in this course
- auto decltype and Type Deduction
- Range-based for nullptr and enum class
- Lambda Expressions Capture Mutable Generic
- Structured Bindings and if-init C++17