Lecture 5 - Slide 33 : 40
Example - Point<C>
We make a type parameterized Point - class
Point<C>
A modest first example...
A type parameterized variant of class Point - point.h.
The implementation of the template class Point - point.cc.
A program that illustrate template instantiation.
A program that illustrate problematic template instantiation.
Compiler errors for the program from above - typical for compilation of template instances with errors.
Lessons learned
The definition of member functions in the template class becomes more complex
See the file
point.cc
Template instantiation first occurs when
Point<int>
,
Point<double>
and
Point<string>
is encountered
For this reason,
point.cc
must be included in
prog.cc
instead of (as usual)
point.h
Compiler error messages from instances of templates are difficult to deal with
It is attractive to provide error messages at a higher level
A template class with friends