daily pastebin goal
23%
SHARE
TWEET

Untitled

a guest Dec 19th, 2018 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # main
  2.  
  3. #include <iostream>
  4. #include "CFoo.h"
  5. #include "CFoo.cpp"
  6.  
  7. int main()
  8. {
  9.     CFoo<int> ciFoo(1);
  10.     CFoo<bool> cbFoo(true);
  11.  
  12.     ciFoo.Hello();
  13.     cbFoo.Hello();
  14.  
  15.     return 0;
  16. }
  17.  
  18. # CFoo.h
  19. #ifndef TEMPLATES_CFOO_H
  20. #define TEMPLATES_CFOO_H
  21.  
  22. #include <iostream>
  23.  
  24. using namespace std;
  25.  
  26.  
  27. template<typename T>
  28. class CFoo
  29. {
  30.  
  31. public:
  32.     CFoo(T val);
  33.  
  34.     void Hello();
  35.  
  36. protected:
  37.     T _val;
  38. };
  39.  
  40.  
  41.  
  42. #endif //TEMPLATES_CFOO_H
  43.  
  44.  
  45. # CFoo.cpp
  46. #include "CFoo.h"
  47.  
  48. template<typename T>
  49. CFoo<T>::CFoo(T val)
  50. {
  51.     _val = val;
  52. }
  53.  
  54.  
  55. template<>
  56. void CFoo<bool>::Hello()
  57. {
  58.     cout << "BOOl" << this->_val;
  59. }
  60.  
  61. template<>
  62. void CFoo<int>::Hello()
  63. {
  64.     cout << "INT" << this->_val;
  65. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top