title: Instantiating a child class as the parent, but calling the child's methods
body: <p>I am writing an application that required the development of an engine for handling data, but the engine had to be replaceable by another depending on the customers' need. Since each customer had very different needs, I wanted to make each engine separated from the others so we could only deliver the application with the engines the customer required.</p>
  
  <p>So my VS Solution has the following projects: App, Engine_Base, Engine_A, Engine_B
  App = the exe
  Engine_Base = the parent class...compiles to a dll and is added to the references of the App through the projec properties
  Engine_A and Engine_B are both child classes of Engine_Base and both compile to a dll of their own (Engine_A.dll, Engine_B.dll). They are not added to references of App so that they will not be loaded at runtime since we do not want to ship both to all our customers.</p>
  
  <p>Based on the configuration file of the customer we decide which engine to load:</p>
  
  <pre><code>Engine_Base^  engine_for_app;
  Assembly^ SampleAssembly;
  Type^  engineType;
  
  if (this-&gt;M_ENGINE == "A")
  {
      SampleAssembly = Assembly::LoadFrom("path\\Engine_A.dll");
  
      engineType = SampleAssembly-&gt;GetType("Engine_A");
      engine_for_app = static_cast&lt;Engine_Base^&gt;(Activator::CreateInstance(engineType, param1, param2));
  }
  else
  {
      SampleAssembly = Assembly::LoadFrom("path\\Engine_B.dll");
  
      engineType = SampleAssembly-&gt;GetType("Engine_B");
      engine_for_app = static_cast&lt;Engine_Base^&gt;(Activator::CreateInstance(engineType, param1, param2, param3, param4));
  }
  </code></pre>
  
  <p>Since only Engine_Base is added to the references of the C++ project we cast our Engine__A or Engine_B objects to the parent type.</p>
  
  <p>Then we set the Events for the threaded execution of our engines as they take a long time to run (lots of data to process):</p>
  
  <pre><code>engine_for_app-&gt;OnComplete += gcnew CompleteEngineProcess(this, &amp;frmMain::ThreadChildComplete);
  engine_for_app-&gt;OnProgressInit += gcnew ProgressInitEngine(this, &amp;frmMain::ThreadChildProgressInit);
  engine_for_app-&gt;OnProgressReport += gcnew ProgressReportEngine(this, &amp;frmMain::ThreadChildProgressReport);
  
  Thread^ aThread;
  aThread = gcnew Thread(gcnew ThreadStart(engine_for_app, &amp;Engine_Base::Read));
  </code></pre>
  
  <p>But this gives me a:</p>
  
  <pre><code>Error   2   error C3754: delegate constructor: member function 'Engine_A::Read' cannot be called on an instance of type 'Engine_Base ^' d:\_activeWork\EDI_TRUNK\src\App\frmMain.cpp    492
  </code></pre>
  
  <p>I realize that this has to do with inheritance, but I'm getting short on ideas of how to fix this.</p>
  
  <p>Does anyone have ideas on how to fix this?</p>
  
  <p>Is our approach an alright solution or should we have been looking at something else and done things differently?</p>