Introduction to OOP | Chapter 18: Generics : | next | previous | audio | real | text |
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(); 12Notice how the programmer filled in the template argument when creating a new variable.