daily pastebin goal
63%
SHARE
TWEET

Untitled

a guest Sep 22nd, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3.  
  4. template <typename T>
  5. class IObserver {
  6.  public:
  7.   virtual void Next(const T& value) noexcept = 0;
  8. };
  9.  
  10. template <typename T1, typename T2>
  11. class BinaryObserver : public IObserver<T1>, public IObserver<T2> {
  12.  public:
  13.   void Next(const T1& value) noexcept override{};
  14.  
  15.   void Next(const T2& value) noexcept override{};
  16. };
  17.  
  18. int main() {
  19.   // This is OK
  20.   BinaryObserver<int, float> mc1;
  21.   mc1.Next(0);
  22.   mc1.Next(0.0f);
  23.  
  24.   // This fails to compile with "multiple overloads"
  25.   BinaryObserver<int, int> mc2;
  26.   mc2.Next(0);
  27.   mc2.Next(0);
  28. }
  29.    
  30. template <typename T>
  31. class BinaryObserver<T, T> : public IObserver<T> {
  32.  public:
  33.   void Next(const T & value) noexcept override{};
  34. };
  35.    
  36. BinaryObserver<int, int> mc2;
  37. mc2.Next(0);
  38. mc2.Next(0);
  39.    
  40. class BinaryObserver : public IObserver<T1>, public IObserver1<T2>
  41. ...
  42. mc2.Next(0);
  43. mc2.Next1(0);
  44.    
  45. template <typename T1, typename T2>
  46. class BinaryObserver : public IObserver<T1>, public IObserver<Shell<T2>> {
  47.  public:
  48.   void Next(const T1& value) noexcept override{T1 t = value;};
  49.   void Next(const Shell<T2>& value) noexcept override{T2 t = value;};
  50. };
  51.  
  52. ...
  53.  
  54.   BinaryObserver<int, float> mc1;
  55.   mc1.Next(0);
  56.   mc1.Next(0.0f);
  57.  
  58.   BinaryObserver<int, int> mc2;
  59.   mc2.Next(0);
  60.   mc2.Next(Shell<int>(0));
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