title: Reference promotion for a derived class with no data members
body: <p>I have an interesting problem involving a hierarchy of classes in a library that I maintain. A very simplified view of the situation is as follows:</p>
  <pre class="lang-cpp prettyprint-override"><code>class Base {
  // private data + public interface to said data 
  };
  
  class ClassA : public Base {
  // Behaviour
  };
  
  class ClassB : public Base {
  // Behaviour
  };
  </code></pre>
  <p>So here I have a class that contains the data privately and has a consistent interface. In reality this is a templated class with lots of different storage models. The two derived classes <code>ClassA</code> and <code>ClassB</code> purely add different implementations of the same behaviour and do not contain any data. It <em>should</em> be within the realms of possibility to convert a reference to an instance of <code>ClassA</code> to one of <code>ClassB</code> without invoking any copies. Of course, one can use</p>
  <pre class="lang-cpp prettyprint-override"><code>ClassA a;
  B&amp; a_bref = *reintepret_cast&lt;B*&gt;(&amp;a);
  </code></pre>
  <p>But this breaks all the rules. My question: Is there a safe way to implement such a conversion operator?</p>