Templates and The Standard Library
- slide 5 : 39
Class templates in C++
In many ways similar to generic classes in C# and Java
Template classes versus classes
A template can be used to create classes by means of
template instantiation
Template instantiation
Supplying actual template parameters
Template parameters to classes must be supplied explicitly
Each instantiation creates a class which has the same status as a hand crafted class
"The generated classes and functions are perfectly ordinary classes that obey all the usual rules for classes"
"... a powerful way of generating code"
"... a certain amount of caution is in order to avoid flooing memory with almost identical [...] definitions"
[Stoustrup page 331]
Type parameters are not related by inheritance
"There are no requirements that different arguments for the same template parameter should be related by inheritance"
, §13.2.1
No constraints on formal type parameters as in C#