Learn how to write a template, what a typename keyword is, and how to specify placeholders for the types used by the template.
- [Instructor] The basic syntax for defining…a template is straightforward.…Here I have a working copy of template-function.cpp…from chapter one of the exercise files.…In this case I've defined a template function.…Let's take a look at the syntax.…The keyword template introduces the template,…and type names are listed in the angle brackets,…separated by commas, so I can have more…than one here.…Though keyword type name or class is interchangeable here,…I tend to use type name, others tend to use class,…just be consistent.…
In this case the type name is named T.…The type name T is an alias that will be replaced…by the type used in the template call down here…on line 16 we call the template with the name…of the function, max of, and we put a type…inside angle brackets.…This is called the template parameters.…This tells the compiler, remember this is a compiler…abstraction, it happens at compile time,…so this tells the compiler what sort of…specialization to use.…
Here a specialization is created…for the max of function using int in place…
- 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.