title: Copy-constructing data members of abstract type
body: <p>Consider the following scenario:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>class AbsBase {
  public:
      virtual double foo() = 0;
  };
  
  class Concrete1 : public AbsBase {
  public:
      double foo() {
          return 1;
      }
  };
  
  class Concrete2 : public AbsBase {
  public:
      double foo() {
          return 2;
      }
  };
  
  struct Config {
      /**
       * Must use a pointer to `AbsBase`, since it is an abstract base class, 
       * and the concrete instances could be of either of the derived classes.
       */
      AbsBase* thing;
  
      void setThing(AbsBase* t) {
          thing = t;
      }
  };
  </code></pre>
  
  <p>This <em>works</em>, but I would prefer it if <code>thing</code> were a copy of the argument passed to <code>setThing</code>. I.e. if <code>thing</code> were of type <code>Concrete1</code> (as opposed to an abstract base class) I could do something like this:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>Concrete1 thing;
  void setThing(const Concrete1&amp; t) {
      thing = Concrete1(t);
  }
  </code></pre>
  
  <p>However I can't see a way of achieving this without instantiating an object of an abstract type (which is illegal). Any ideas?</p>