title: Thread and interfaces C++
body: <p>I have some issue to create different threads using interfaces and factory:</p>
  
  <p>I have two interfaces that are derived (here by one class but eventually more..). I use a factory to create an object of the desired derived class.
  As I run them within different threads, I used what the factories return me to give as parameter of the thread constructor.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;thread&gt;
  
  class Base
  {
      public:
          virtual ~Base () {}
  
          virtual void operator () () = 0;
  };
  
  
  class Derived : public Base
  {
      public:
          virtual void operator () ()
          {
              std::cout &lt;&lt; "Derived of Base!" &lt;&lt; std::endl;
          }
  };
  
  enum BaseType
  {
      derived = 1000
  };
  
  class BaseFactory
  {
      public:
          static Base *createBase (BaseType bt)
          {
              switch (bt)
              {
                  case derived:
                      return new Derived;
                  default:
                      return NULL;
              }
          }
  };
  
  
  class OtherBase
  {
      public:
          virtual ~OtherBase () {}
  
          virtual void operator () () = 0;
  };
  
  class OtherDerived : public OtherBase
  {
      public:
          virtual void operator () ()
          {
              std::cout &lt;&lt;  "OtherDerived of OtherBase!" &lt;&lt; std::endl;
          }
  };
  
  enum OtherBaseType
  {
      otherderived = 1100
  };
  
  class OtherBaseFactory
  {
      public:
          static OtherBase *createOtherBase (OtherBaseType obt)
          {
              switch (obt)
              {
                  case otherderived:
                      return new OtherDerived;
                  default:
                      return NULL;
              }
          }
  };
  
  
  
  int main (int argc, const char *argv[])
  {
      Base *pBase = BaseFactory::createBase(derived);
      OtherBase *pOBase = OtherBaseFactory::createOtherBase(otherderived);
  
      std::thread *t1 = new std::thread ((*pBase)());
      std::thread *t2 = new std::thread ((*pOBase)());
  
      t1-&gt;join();
      t2-&gt;join();
  
      delete t1;
      delete t2;
  
      return 0;
  }
  </code></pre>
  
  <p>When compiling, I have an issue at the creation of each thread:</p>
  
  <pre><code>test.cxx:87:50: error: invalid use of void expression
  test.cxx:88:51: error: invalid use of void expression
  </code></pre>
  
  <p>I believe the problem comes from I give as parameter to create threads object of type Base and OtherBase (thus the interfaces).
  However I don't really know how to solve this problem.</p>