title: Using interface to export class from dll
body: <p>IClass (My interface):</p>
  
  <pre><code>#ifndef _ICLASS_H
  #define _ICLASS_H
  
  #include &lt;sstream&gt;
  
  namespace Test
  {
      class __declspec(dllexport) IClass
      {
      public:     
          virtual ~IClass() {}                
  
          virtual bool Init(const std::string &amp;path) = 0;     
      };
  }
  
  #endif
  </code></pre>
  
  <p>Class.h</p>
  
  <pre><code>#ifndef _CLASS_H
  #define _CLASS_H
  
  #include "IClass.h"
  #include &lt;memory&gt;
  #include &lt;sstream&gt;
  #include &lt;stdio.h&gt;
  
  namespace Test
  {
      class Class: public IClass
      {
      public:
          Class();
          ~Class();               
  
          bool Init(const std::string &amp;path);         
      };
  }
  
  #endif
  </code></pre>
  
  <p>Class.cpp</p>
  
  <pre><code>#include "Class.h"
  
  namespace Test
  {
      Class::Class()
      {       
      }
  
      bool Class::Init(const std::string &amp;path)
      {
          try
          {
              // do stuff
  
              return true;
          }
          catch(std::exception &amp;exp)
          {
              return false;
          }
      }   
  }
  </code></pre>
  
  <p><strong>main</strong> (in exe, dll linked implicitly)</p>
  
  <pre><code>#include "IClass.h"
  
  using namespace Test;
  
  int main(int argc, char* argv[])
  {
      std::shared_ptr&lt;IClass&gt; test = std::make_shared&lt;Class&gt;(); // error: unreferenced Class
  
      test-&gt;Init(std::string("C:\\Temp"));
  }
  </code></pre>
  
  <p>At the moment Class is not declared </p>
  
  <p>-> if I include <code>Class.h</code> to main following error occurs: <code>LNK2019: unresolved external symbol</code>: add <code>class __declspec(dllexport) Class : public IClass</code> resolve this linker issue, but is it ok to do it this way?</p>
  
  <p>-> I also can't do this: <code>std::shared_ptr&lt;IClass&gt; test = std::make_shared&lt;IClass&gt;();</code>
  (because it's not allowed to create an object of abstract class)</p>
  
  <p>How can I solve this issue and is this best practise?</p>