Two of the biggest features added to C++11 were auto type deduction and uniform list initialization. Troy explains both of them and what is the best way to use them.
- [Instructor] The keyword auto tells a compiler…to deduce the type of variable…by the expression used to initialize it.…Unlike other types,…auto requires the variable to be initialized,…so there's no chance of a variable…running around uninitialized,…preventing a difficult-to-find bug.…Auto also helps us to write our code to interfaces…and not to implementations, avoiding tight coupling.…If you need a specific type,…you can use auto with type initialization.…Let's take a look at a few examples.…
Let's try to create a vector event.…First, we initialize alpha to a vector event…with the values one, two, and three.…We try to do something similar with auto…but we get a syntax error.…Since initialization of auto…expects one expression, not three.…We then try to declare gamma…with auto and an initializer list.…The compiler is okay with it, but we created a variable…of type initialize list event, not vector event.…
Then we defined delta with a vector event…and an initialize list, that works,…and gives us what we were looking for.…
- Major new C++ features
- Turning on modern C++
- Letting the compiler help
- Using the new features correctly
- Using auto type deduction
- Using lambdas
- Range-based for loops
- How C++ and the Standard Template Library name things
- Making the best of the filesystem library
- Managing objects
Skill Level Beginner
1. What Is Modern C++?
2. Tools That Improve Your Code
3. Using the New Features Correctly
4. Don't Reinvent the Wheel
5. Managing Objects
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.