Learn about argument deduction and how this impacts your use of template arguments in function calls.
- [Instructor] When you call a template function,…the compiler must know the types of any arguments,…but that doesn't mean you always need to specify…all the types.…If the compiler can easily deduce the types,…then you don't need to specify them at all,…this is called template argument deduction,…and here I have a working copy of…template-function.cpp from chapter one…of the exercise files, and you notice down here…on line 16, I'm calling our max of template function,…and I provided the type of int in the template arguments.…
So when I build and run, you notice…that it knows that this is of type int,…and everything works fine.…What's interesting though is that it's easy…for the compiler to deduce this type…from the context, because I'm passing it two ints.…So if I remove that template argument…and the angle brackets, and I save, and build, and run,…you notice that it still works just fine,…and this is because the compiler is able…to deduce this type from the context.…
So here's another more practical example.…I'm going to include the vector header,…
- 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.