Enums in previous versions of C++ were loosely defined types. Strongly typed enums behave properly as their own type. In this video, Troy explains why this is a very good thing.
- [Man] Enum classes are strongly typed,…unlike traditional enums,…and they don't pollute the surrounding scope.…Redefinition of enumerators…is no longer an issue as well.…Implicit conversions are not allowed…with enum class.…Prefer enum class to traditional enums.…Let's take a look at a code sample.…Traditional enums are weakly typed,…so we can't have two enumerators…with the same definition…in the same name space.…So here we have a traffic light…with colors red, green, and yellow.…
Here we have a car color…with black, white, gray, and silver…but look what happens once soon as I…comment in green,…we notice that we get the error right away.…Redefinition of enumerator green…and it's saying that hey,…I've got it defined here…and you can't also have it defined here.…And that's kind of a problem.…The enum class has no problem with enumerators…of the same name.…Dog is defined in both pet and mammal.…So here's dog in pet.…Here's dog in mammal.…
And it's not a problem.…Now you notice that…even though we're not using scope resolution,…
- 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?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
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.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.