Notes on VectorN


VectorN illustrates how we can use templates which the compiler can use to generate specific class instances.
The template argument, size, in this example is a constant expression of type unsigned which represents the dimension of the vector.
The first time the compiler encounters a token like Vector<2> it instantiates a Vector<2> class from the template
template <unsigned size> class Vector

Advantages of template classes are that compiler generated code is less error-prone, type safety is preserved and they are useful for implementing "container" classes.
Other forms of template arguments are permitted. The most common is to use a type name. List<int> might be a list of integers instantiated from the template class
template <class T> class List

Multiple template arguments are permitted.
Template notation can lead to very complicated-looking class names e.g. List< Vector< int, 2 > >. We can define synonyms however (using typedef).