title: Overload a C++ reference cast (downcasting inheritance)
body: <p>Is is possible to overload a reference cast in C++?</p>
  
  <p>I've got code I can't touch in the format:</p>
  
  <pre><code>void someMethod(Parent&amp; parentReference, ...){
      ...
      Child&amp; child = static_cast&lt;Child&amp;&gt;(parentReference);
  </code></pre>
  
  <p>(The class Child inherits directly and publicly from the class Parent)</p>
  
  <p>I'd like to adjust the behavior of this cast - I can modify the class Child.<br>
  I've tried overloading the cast operator like so:</p>
  
  <pre><code>Parent::operator Child&amp;(){
      ...
  </code></pre>
  
  <p>But this method never gets called.</p>
  
  <p>I'm starting to wonder if this is even possible?</p>
  
  <p><strong>EDIT</strong><br>
  Per R Sahu, I'm close to this scenario:
  <a href="https://timsong-cpp.github.io/cppwp/n3337/expr.static.cast#2" rel="nofollow noreferrer">https://timsong-cpp.github.io/cppwp/n3337/expr.static.cast#2</a></p>
  
  <pre><code>struct B { };
  struct D : public B { };
  D d;
  B &amp;br = d;
  
  static_cast&lt;D&amp;&gt;(br);            // produces lvalue to the original d object
  </code></pre>
  
  <p>Except that instead of simply assigning <code>B &amp;br = d;</code>, <code>br</code> comes into the method as an argument, and is previously sent over the network (as NML). </p>
  
  <p>This would be the scenario:</p>
  
  <pre><code>struct B { };
  struct D : public B { 
     int a;
     int b
  };
  
  D d;
  d.a = x;
  d.b = y;
  
  server.send(d); 
  
  ...
  
  client.receive(msg);
  
  receive(B&amp; msg){
  
    D&amp; msgD = static_cast&lt;D&amp;&gt;(msg);
  
  }
  </code></pre>
  
  <p><code>msgD.x</code> and <code>msgD.y</code> come over the wire and are reconstructed properly.  However, I would like to change the way they are reconstructed, without modifying the <code>receive</code> method.  Is this possible?</p>