Learn what a template variable is and how it works. Also, discover the benefit of a template variable and when you should use it.
- C++ 14 provides a new template implementation…for strongly typed variables.…Here I have a working copy of template-variable.cpp…from Chapter one of the exercise files,…and this will only work in C++ 14 or later.…Here we have a template variable.…We have our normal template syntax…followed by a variable of type T,…and in this case we're defining pi to 20 places.…Down here we're setting cout to use a precision of 20 places…for our floating point variables.…
And we are using this variable with the double type.…So when I build and run this,…of course double does not have 20 places of precision,…after 16 places or so it starts to go funny.…Now if I change this to long double,…now the long double type on this machine…uses an 80 bit float, which will provide…the full 20 digits of precision.…On many systems, including Microsoft Windows,…it still uses a 64 bit flow…which will not be any different than double.…
But here on this system when I build and run,…you notice that I'm getting all 20 digits…of our pi correctly because I'm using a long double.…
- Template fundamentals
- STL containers
- Accessing iterators
- Output, forward, and bidirectional iterators
- The transform function
- Transforming strings and types
- Arithmetic, relational, and logical functions
- STL algorithms
Skill Level Intermediate
2. STL Containers
3. STL Iterators
5. STL Functions
6. STL Algorithm
- 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.