title: How does pure virtual functions mechanism in c++ exposes functions from DLL
body: <p>Consider the next c++ code fragment </p>
  
  <p><strong>1. In an EXE:</strong></p>
  
  <p><strong>Base.hpp</strong></p>
  
  <pre><code>#ifndef _BASE_H_
  #define _BASE_H_ 
  class Base
  {
      public:
      Base(){};
      virtual double Add(double &amp;x, double &amp;y) = 0; 
  
  };
  #endif
  </code></pre>
  
  <p><strong>main.cpp</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "Base.hpp"
  #include "DerivedFactory.hpp"
  void main()
  {
      Base *theBase = DerivedFactory::Create();
      double x = 4.9, y = 3.3,z;
      z = theBase-&gt;Add(x, y);//Works when Add is pure virtual function, but how??? 
                             //Linker error when Add is not pure virtual
  }
  </code></pre>
  
  <p><strong>2. In an implicitly linked DLL</strong></p>
  
  <p><strong>Derived.hpp</strong></p>
  
  <pre><code>#ifndef _DERIVED_H_
  #define _DERIVED_H_
  #include "Base.hpp"
  class Derived : public Base
  {
      public:
      double Add(double &amp;x, double &amp;y);
  };
  #endif
  </code></pre>
  
  <p><strong>DerivedFactory.hpp</strong></p>
  
  <pre><code>#ifndef _DERIVEDFACTORY_H_
  #define _DERIVEDFACTORY_H_
  #include "Derived.hpp"
  
  class DerivedFactory
  {
      public:
      __declspec(dllexport) static  Derived* Create();
  };
  #endif
  </code></pre>
  
  <p><strong>Derived.cpp</strong></p>
  
  <pre><code>#include "Derived.hpp"
   double Derived::Add(double &amp;x, double &amp;y)
  {
      return x + y;
  }
  </code></pre>
  
  <p><strong>DerivedFactory.cpp</strong></p>
  
  <pre><code>#include "DerivedFactory.hpp"
  Derived* DerivedFactory::Create()
  {
      Derived* theDerived = new Derived;
      return theDerived;
  }
  </code></pre>
  
  <ol>
  <li><p>The main question is how does the exe "know" to address the correct implementation of Add from the dll when the only exported function from it is Create()?</p></li>
  <li><p>Why do I get linker error when Add() is "just" virtual and not pure virtual?</p></li>
  </ol>