title: Abstract Class Hierarchy and Access Violation
body: <p>The background to this is that I am attempting to re-factor a complex C++ application. I have put together the code below as a trimmed down version of the code I am working with (cutting out the irrelevent methods etc.). I am probably doing something stupid as I have not touched C++ in years, but I can see what... </p>
  
  <p>I have the following classes </p>
  
  <p><strong>message_sink.h:</strong></p>
  
  <pre><code>class IMessageSink
  {
  public:
      virtual ~IMessageSink() { };
      virtual void process(const Message&amp; msg) = 0;
  };
  </code></pre>
  
  <p>with the following base class </p>
  
  <p><strong>model_base.h:</strong></p>
  
  <pre><code>class Model : public virtual IMessageSink
  {
  public:
     Model(Tag a);
  
     virtual Model* makeA(Tag a) = 0;
     void reset();
  
  private:
     friend class EM;
  
     const Tag _a;
     virtual void calculate(double lambda) = 0;
  };
  </code></pre>
  
  <p>where <strong>model_base.cpp</strong> is </p>
  
  <pre><code>Model::Model(Tag a) : _a(a) { }
  
  void Model::reset()
  {
     // ... some implementation
  }
  
  void Model::process(const Message msg)
  {
      // ... some implementation
  }
  </code></pre>
  
  <p>I then have the following classes inheriting from the base class</p>
  
  <p><strong>model_m0.h:</strong></p>
  
  <pre><code>class ModelM0 : public virtual Model
  {
  public:
      ModelM0(Tag a);        
      ModelM0* make(Tag a);
  
  private:
      void calculate(double lambda);
  };
  </code></pre>
  
  <p><strong>model_m0.cpp:</strong></p>
  
  <pre><code>ModelM0::ModelM0(Tag a) : Model(a) { }
  
  ModelM0* ModelM0::make(Tag a)
  {
     ModelM0* m = new ModelM0(a);
     m-&gt;reset();
     return m;
  }
  
  void ModelM0::calculate(double lambda)
  {
      // Some code...
  }
  </code></pre>
  
  <p>But here is where the problems lies, I have another class called <code>ModelM0Holder</code> and this is defined as </p>
  
  <p><strong>model_m0_holder.h:</strong></p>
  
  <pre><code>class ModelM0Holder : public IMessageSink
  {
  public:
      static ModelM0Holder* make(Tag a)
      {
          return new ModelM0Holder(a);
      }
      ModelM0Holder(Tag a);
      ~ModelM0Holder();
      void process(const Message&amp; msg);
  
  private:
      ModelM0* getModel(int line);
  };
  </code></pre>
  
  <p>and <strong>model_m0_holder.cpp:</strong> is </p>
  
  <pre><code>ModelM0Holder::ModelM0Holder(Tag a) : _a(a) { } 
  
  ModelM0Holder::~ModelM0Holder()
  {
      // ... some implementation
  }
  
  void ModelM0Holder::process(const Message&amp; msg)
  {
      // ... some implementation
  }
  
  ModelM0* ModelM0Holder::getModel(int ag)
  {
      ModelM0* m;
      m = m-&gt;make(_a); // Access Violation Exception.
      // ... 
  }
  </code></pre>
  
  <p>When I call <code>ModelM0Holder::getModel</code> I get an <code>AccessViolationException</code>, I can't call this function, why?</p>
  
  <p>Thanks very much for your time. </p>