Advertisement
Guest User

template

a guest
Feb 28th, 2020
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. template <typename T>
  4. struct Bad {
  5.     friend std::ostream& operator <<(std::ostream& os, const Bad<T>& a);
  6. };
  7.  
  8. template <typename T>
  9. std::ostream& operator <<(std::ostream& os, const Bad<T>& bad) {
  10.     (void)bad;
  11.     return os << "i'm bad";
  12. }
  13.  
  14.  
  15.  
  16.  
  17.  
  18. template <typename T>
  19. struct Ok {
  20.     template <typename X>
  21.     friend std::ostream& operator <<(std::ostream& os, const Ok<X>& a);
  22. };
  23.  
  24.  
  25.  
  26.  
  27.  
  28. template <typename T>
  29. std::ostream& operator <<(std::ostream& os, const Ok<T>& ok) {
  30.     (void)ok;
  31.     return os << "i'm ok";
  32. }
  33.  
  34. int main() {
  35.     std::cout << Ok<int>() << std::endl;
  36.     //std::cout << Bad<int>() << std::endl;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement