$\require{cancel}$
Class Templates
Stroustrup says
Templates add flexibility
They have nearly optimal performance.
One word of caution, the compiler will not generate code that is not needed.
So if you don't test thoroughly, you may have a syntax error in your code you do not discover.
This is particularly problematic if you have a class method that is not called.
The standard container library is built on top of this.
Again, we will study this in more detail later.
The basic concept remains the same
To keep things familiar you can do the class declaration and class implementation in different steps (ie the old .h and .cpp file)
You will need to each function in separate
template
statements
And you will need the strange construct
template < typename T> FooT<T>:FooT () { }
Look at
ArrayT.h
I wrapped everything in a
template
wrapper,
made the changes above,
deleted ItemType and changed all ItemTypes to T
In the test file, I needed to make a few small changes.
ArrayT
became
ArrayT<int>