Lecture overview -- Keyboard shortcut: 'u'  Previous page: Class templates in C++ -- Keyboard shortcut: 'p'  Next page: Function templates -- 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 6 : 39
Notes about C++
Templates and The Standard Library
Example - Point<C,dim,default_value>

We make a Point class parameterized with a type C, an integer dimension, and some default value in C

All template parameters are defaulted

y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/templates/vers4/point.hA type parameterized variant of class Point - point.h.


y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/templates/vers4/point.ccThe implementation of the template class Point - point.cc.


y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/templates/vers4/prog.ccA program that illustrate the template instantiation.


  • Lessons learned

    • It is only possible to pass template constant parameters of integer type

      • The compiler disallows a constant of type double

    • The details in point.cc becomes even more challenging

    • Tricky to deal with the overloading of operator<< as a friend and template function

      • The compiler helps a bit...