title: Method in superclass that returns instance of subclass
body: <p>This question is the equivalent of Java's <a href="https://stackoverflow.com/questions/28820288/how-to-make-superclass-method-returns-instance-of-subclass">How to make Superclass Method returns instance of SubClass</a></p>
  
  <p>Suppose this class hierarchy:</p>
  
  <pre><code>class A
  {
      public:
          A makeCopyOfObject();
  };
  class B: public A
  {
      public:
          void doSomethingB();
  };
  class C: public A
  {
      public:
          void doSomethingC();
  };
  </code></pre>
  
  <p>I'd like to use it this way:</p>
  
  <pre><code>B().makeCopyOfObject().doSomethingB();
  C().makeCopyOfObject().doSomethingC();
  </code></pre>
  
  <p>But of course I can't, because the <code>makeCopyOfObject</code> function returns an instance of <code>A</code>, not an instance of a subclass.</p>
  
  <p>I surely could write two versions of the function in the two subclasses, but the code would be the same, except for the return type, because all fields to be copied and modified are in the base class. So, is there an alternative?</p>