title: How to initialize a "bad" empty reference to abstract class
body: <p>I'll get straight to it: I have a class template that holds a reference and updates info to it:</p>
  
  <pre><code>template&lt;class T&gt;
  class Parser {
      T&amp; m_ref;
  public:
      typedef T ValueType;
      Parser(T&amp; ref): m_ref(ref) {}
      virtual void read(std::istream&amp;);
  };
  </code></pre>
  
  <p>Now, I have another template that creates a new object and updates it using this interface, to do so I have a field that saves the parser.
  However, I'd like to use updater to classes that derive from T, which is impossible with poymorphism since <code>Parser&lt;Derived&gt;</code> does not inherit from <code>Parser&lt;Base&gt;</code>.
  I created this work-around that uses an intermediate class that inherits from <code>Parser&lt;Base&gt;</code> but updates into a <code>Parser&lt;Derived&gt;</code>:</p>
  
  <pre><code>template&lt;class T&gt;
  struct dummy {};
  template&lt;class T&gt;
  class Creator {
      typedef shared_ptr&lt;Parser&lt;T&gt; &gt; ParserPtr;
      typedef shared_ptr&lt;T&gt; ValuePtr;
  
      ValuePtr m_output;
      ParserPtr m_parser;
  
      template&lt;class ParserType&gt;
      class LocalParser : public Parser&lt;T&gt; {
          ParserType m_parser;
      public:
          LocalParser(typename ParserType::ValueType&amp; val):
              Parser&lt;T&gt;(/*???*/), //problems start here, I must initialize the base
              m_parser(val) {}
          void read(std::istream&amp; is) { //use polymorphism to update into some derieved reference
              m_parser.read(is);
          }
      };
  public:
      Creator(): //Uses Parser&lt;T&gt; as default parser
          m_output(new T), 
          m_parser(new Parser&lt;T&gt;(*m_output)) {}
      template&lt;class ParserType&gt;
      Creator(dummy&lt;ParserType&gt;) { //Use any parser
          auto temp = make_shared(new typename ParserType::ValueType);
          m_output = temp;
          m_parser = maked_shared(new LocalParser&lt;ParserType&gt;(*temp));
      }
      virtual ValuePtr read()(std::istream&amp; is) {
          m_parser-&gt;read(is);
          return m_output;
      }
  };
  </code></pre>
  
  <p>Basically <code>LocalParser</code> is an intermediate class that inherits from <code>Parser&lt;T&gt;</code> but updates a diffrent reference from the one it's base holds.
  The problem here is how to initialize <code>Parser&lt;T&gt;</code>, especially when <code>T</code> is abstract (which is 99% of the time I actually use this class with a derived parser).</p>
  
  <p>My question boils down to "how to define a reference to a (possibly) abstract class that WON'T be used?" (or is there any kind of other work around where I don't define an intermidiate that inherits from <code>Parser&lt;T&gt;</code>).</p>
  
  <p><strong>EDIT</strong>: The Parser interface is a separate code I cannot change.</p>