Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include <string>
  2. #include <iostream>
  3.  
  4. template <class T>
  5. class Classsy
  6. {
  7. public:
  8.     Classsy(T x){
  9.       this->x = x;
  10.     }
  11.     void doSomething();
  12.   T x;
  13. };
  14.  
  15. template <class T>void Classsy<T>::doSomething(){
  16.   std::cout << x+x << std::endl;
  17. }
  18.  
  19. template <> void Classsy<std::string>::doSomething() {
  20.   std:: cout << x << std:: endl;
  21. }
  22.  
  23.  
  24. int main(int argc, char const *argv[]) {
  25.   Classsy <int> kupa(5);
  26.   Classsy <std::string> dupa("sdsd");
  27.   kupa.doSomething();
  28.   dupa.doSomething();
  29.  
  30.   return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement