Lecture overview -- Keyboard shortcut: 'u'  Previous page: Templates [Section] -- Keyboard shortcut: 'p'  Next page: Templates versus generics in Java, C# and C++ -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Help page about these notes  Alphabetic index  Course home  Lecture 5 - Page 2 : 39
Notes about C++
Templates and The Standard Library
Templates

Templates in C++ provide for compile-time parametrization of functions and classes

Templates correspond to generic types and generic methods in Java and C#

  • Template parameters

    • Types

    • Values of template types

    • Constants of integer types

    • Pointer to an object, a pointer to function, or pointer to a member

    • It is not possible to pass, doubles, floats, or string constants as a template arguments

  • Template specialization

    • It is possible to define several specializations (variants) of a template distiguished by a 'formal type parameter pattern'

    • Can be used to provide a shared template for all pointer types

    • Both for class and function templates

The C++ template facility is macros that look like classes [Anders Hejlsberg].