template class with generic parameter
#include <iostream> using namespace std; template<class T> class Distance { public: Distance(T distance); void show_distance(void) { cout << "The distance is " << distance << " miles\n"; }; private: T distance; }; template<class T> Distance<T>::Distance(T distance) { Distance::distance = distance; }; int main(void) { Distance<int> short_distance(100); Distance<long> long_distance(2000000L); short_distance.show_distance(); long_distance.show_distance(); }