title: Call a class method like a thread
body: <p>I'm using SDL, but i accept any solution with other libraries if it is possible (pthread, boost_thread...).
  I have a class:</p>
  
  <pre><code>class c_image
  {
      public:
          bool _flag_thread;
          int  _id;
          void load (void);
      private:
          int thread_func (void*);
  }
  
  c_image::load (void)
  {
      SDL_Thread* thread_1;
      if (flag_thread)
          thread_1 = SDL_CreateThread (c_image::thread_func, NULL);
      else
          thread_func (NULL);
  }
  
  c_image::thread_func (void* data)
  {
      _id = 1;
      ....
      return 0;
  }
  </code></pre>
  
  <p>The problem is that if <code>flag_thread</code> is false, it execute <code>thread_func</code> like a normal function and it works fine, but if <code>flag_thread</code> is true, i need that call in a different thread and i have no idea how to make it. The line of <code>SDL_CreateThread</code> return an error. I need the thread of the method because inside the <code>thread_func</code> i need to modify elements like <code>_id</code> that is a member of the class, and if i make the thread outside of the class i don't have access to <code>_id</code>.</p>
  
  <p>Thanks.</p>
  
  <p>Edit:
  This is how I have it now, and not find a way to make it work:</p>
  
  <pre><code>class c_image
  {
      public:
          bool _flag_thread;
          int  _id;
          void load (void);
      private:
          static int thread_func_wrapper (void* data);
          int thread_func (void);
  }
  
  void c_image::load (void)
  {
      SDL_Thread* thread_1;
      if (flag_thread)
          thread_1 = SDL_CreateThread (thread_func_wrapper, NULL, this);
      else
          thread_func();
  }
  
  int c_image::thread_func_wrapper (void* data)
  {
      c_image* self = static_cast&lt;c_image*&gt;(data);
      return self-&gt;thread_func();
  }
  
  int c_image::thread_func (void)
  {
      printf ("id: %d", _id);
      ....
      return 0;
  }
  </code></pre>
  
  <p>Now it seems it work fine. I will continue doing tests. Thanks you very much!</p>