Learn about the compile-time impact of templates and what considerations you need to be aware of when using header files.
- [Instructor] If you're familiar with defining classes…in C++, you may try to define a template class…in a header file,…and the template class implementation in a separate file,…as in this example.…Here we have a great application for templates.…It's a stack type, a stack class, and it will implement…a very simple, fixed size LIFO stack using a template.…So, it should work with any type.…And we've got the header file here, with the interface,…and we have a cpp file here with the implementation,…and then we use it here from this template-class.cpp.…
Now, the problem with this is that, well, it doesn't work.…When I tried to build, you'll notice that build fails.…And the error I get here is linker command failed,…with exit code one, and there's actually a very…reasonable explanation for this.…So we have the stack interface to find,…or the class interface to find in this file, stack.h.…And so the compiler processes the header file,…and it generates specializations for the template class.…
And then, the compiler processes the cpp file,…
- 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.