Learning about templates
Another technique to add to your toolbox of programming concepts that we will use in the next section is the idea of templates. Templates are a way for you to be able to create generic classes that can be extended to have the same functionality for different datatypes. It's another form of abstraction, letting you define a base set of behavior for a class without knowing what type of data will be used on it. If you've used the STL before, you've already been using templates, perhaps without knowing it. That's why the list class can contain any kind of object.
Here's an example of a simple templated class:
#include <iostream> // std::cout template <class T> class TemplateExample { public: // Constructor TemplateExample(); // Destructor ~TemplateExample(); // Function T TemplatedFunction(T); };
In this case, we created our TemplateExample
class and it has three functions. The constructor and deconstructor look normal, but then I have...