home *** CD-ROM | disk | FTP | other *** search
/ Using Visual C++ 4 (Special Edition) / Using_Visual_C_4_Special_Edition_QUE_1996.iso / ch14 / templts.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-18  |  762 b   |  43 lines

  1. // Templts.cpp
  2.  
  3. #include <iostream.h>
  4. #include "templts.h"
  5. #include "contents.h"
  6.  
  7. // Constructor
  8. template <class T>
  9. RailroadCar<T>::RailroadCar(int NewCarNumber,
  10.                             T&  NewContents)
  11. {
  12.     CarNumber = NewCarNumber;
  13.     pContents = &NewContents;
  14. }
  15.  
  16. // Destructor
  17. template <class T>
  18. RailroadCar<T>::~RailroadCar()
  19. {
  20.     Unload();
  21. }
  22.  
  23. // Public member functions
  24. template <class T>
  25. void RailroadCar<T>::ShowContents()
  26. {
  27.     cout << "Railroad car #" << CarNumber;
  28.     cout << " is filled with " << pContents->isA();
  29.     cout << "s\n";
  30. }
  31.  
  32. template <class T>
  33. T* RailroadCar<T>::Unload()
  34. {
  35.     T* temp = pContents;
  36.     pContents = NULL;
  37.     return temp;
  38. }
  39.  
  40. // Force instantiation of templates
  41. template RailroadCar<Cow>;
  42. template RailroadCar<Passenger>;
  43.