Week 3a - C++ Templates

Supports Generic Programming

Synopsis:

This lecture provides an introduction to C++ Template functions and classes. We will cover basic ideas in a presentation and then discuss code examples.

Readings and Activities for the Week:

Glossary of Terms

Lecture Content:

  1. Projects:

  2. Focus for this Lecture - C++ Templates

    Quick overview

    Templates Presentation, pptx
    Templates are one of the terrific features of the C++ language. Almost all of the Standard Template Library (STL) is implemented with templates, and they are very useful in day-to-day programming.

    fully functional C++ Properties, courtesy of templates
    This project demonstrates how easy it is to extend the C++ language. C++ doesn't natively support properties but it's not hard to provide them.

    First template demo
    Provides a simple type to string conversion facility.

    Template Code Examples
    Basic and some more advanced template examples.

    STL Container examples
    This code contains a simple example of the new Variadic Template functionality in the "inserter" project.

    Survey of STL Container Classes
    Simple demos of almost all of the STL containers.

    STL Template-based Functors and Algorithms
    Another set of template code examples, including functors, algorithms, and several other things you need to know.

    Functor examples

    Excellent template Q&A
    This is a good place to find information to supplement class texts and notes.

  3. XML:

  4. Preparation for Synchronous Discussion:

    • Download, build, and run the Parser project.
    • Be prepared to describe how this code works. You will find the Parser Blog helpful.
  5. Lecture Take-away

    The most important things we discussed today are: Next time we will continue with class relationships. Please look at: