Introduction to OOP Chapter 18: Generics : next previous audio real text

Template Classes

While template functions are useful, it is more common to use templates with classes.
template <class T> class Box {
public:
	Box (T initial) : value(initial) { }
	T getValue() { return value; }
	setValue (T newValue) { value = newValue; }
private:
	T value;
};

	Box<int> iBox(7);
	cout << iBox.getValue();
7
	iBox.setValue(12);
	cout << iBox.getValue();
12
Notice how the programmer filled in the template argument when creating a new variable.
Intro OOP, Chapter 18, Slide 04