title: Passing by reference: child of multiple interfaces
body: <p>I'm getting build errors when passing an object that implements multiple interface to a function that requires only one of the interfaces.  </p>
  
  <p>I'm developing a communication package.
  The package has a Receiver class and a Sender Class.  The Receiver class uses a notification interface Receive_Notifier (function object) for handling notifications.  Likewise the Sender class uses a notification interface Send_Notifier to handling notifications.  </p>
  
  <pre><code>interface Send_Notifier
  {
      void sending_text(string text);
  }
  
  interface Receive_Notifier
  {
      void raw_text_received(string raw_text);
  }
  
  class Sender
  {
      Send_Notifier m_notifier = null;
      public Sender(ref Send_Notifier notifier)
      {
          m_notifier = notifier;
      }
      public void send(string text)
      {
          m_notifier.sending_text(text);
          return;
      }
  }
  
  class Receiver
  {
      Receive_Notifier m_notifier = null;
      public Sender(ref Receive_Notifier notifier)
      {
          m_notifier = notifier;
      }
      public void receive(string text)
      {
          m_notifier.raw_text_received(text);
          return;
      }
  }
  </code></pre>
  
  <p>I have combined the interfaces into a Communications_Notifier:</p>
  
  <pre><code>interface Communications_Notifier
      : Send_Notifier, Receive_Notifier
  {
  }
  </code></pre>
  
  <p>I created a <code>Notifier</code> class that implements the <code>Communications_Notifier</code> interface:  </p>
  
  <pre><code>class Notifier
      : Communications_Notifier
  {
      public void sending_text(string text)
      {
          System.Console.WriteLine("--&gt; " + text);
      }
      public void raw_text_received(string raw_text)
      {
          System.Console.WriteLine("&lt;-- " + raw_text);
      }
  }
  </code></pre>
  
  <p>To simplify this post, I'll only show the sender class:</p>
  
  <pre><code>class Sender
  {
      Send_Notifier m_notifier = null;
      public Sender(ref Send_Notifier notifier)
      {
          m_notifier = notifier;
      }
      public void send(string text)
      {
          m_notifier.sending_text(text);
          return;
      }
  }
  </code></pre>
  
  <p>The issue is when I pass an instance of the <code>Notifier</code> to an instance of the <code>Sender</code> class:  </p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          Notifier the_notifier = new Notifier();
          Sender talker = new Sender(ref the_notifier); // ** Error generating line
  
          talker.send("Hello\n");
  
          string pause_text;
          pause_text = System.Console.ReadLine();
      }
  }
  </code></pre>
  
  <p>The errors from Visual C# Express 2010:</p>
  
  <pre><code>Error   1   The best overloaded method match for 'Multiple_Inheritance_Interface.Sender.Sender(ref Multiple_Inheritance_Interface.Send_Notifier)' has some invalid arguments    C:\Users\Thomas\Programming_Experiments\C_Sharp\Multiple_Inheritance_Interface\Multiple_Inheritance_Interface\Program.cs    55  29  Multiple_Inheritance_Interface  
  Error   2   Argument '1': cannot convert from 'ref Multiple_Inheritance_Interface.Notifier' to 'ref Multiple_Inheritance_Interface.Send_Notifier'   C:\Users\Thomas\Programming_Experiments\C_Sharp\Multiple_Inheritance_Interface\Multiple_Inheritance_Interface\Program.cs    55  44  Multiple_Inheritance_Interface
  </code></pre>
  
  <h2>Questions:</h2>
  
  <ol>
  <li>Why can't the <code>Notifier</code> be
  converted to a reference of type
  <code>Sender</code>, since it implements the
  <code>Sender</code> interface?</li>
  <li>Why is the argument to the
  constructor invalid?</li>
  </ol>
  
  <p><em>Note:  I'm transitioning from a C++, C and Java background to C#.</em></p>