Advertisement
Felanpro

Template Specializations

May 2nd, 2016
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. template<class T>
  6. class Airplane
  7. {
  8. public:
  9.     Airplane(T x)
  10.     {
  11.         cout << x << " is not a character." << endl;
  12.     }
  13. };
  14.  
  15. template<>
  16. class Airplane<char>
  17. {
  18. public:
  19.     Airplane(char x)
  20.     {
  21.         cout << x << " is indeed a character." << endl;
  22.     }
  23. };
  24.  
  25. int main()
  26. {
  27.     Airplane<int> obj1(7);
  28.     Airplane<double> obj2(3.154);
  29.     Airplane<char> obj3('A');
  30.  
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement