title: C++ create thread function with params results in converting errors
body: <p>I am doing my first steps in C++ multi threading and ran into a problem.
  What I wouyld like to achieve is set out tasks with parameters that will be running in separate threads.
  Googling for answers did not bring me the answer.</p>
  <p>The system I am using consists of Windows 10 Pro, and Code::Blocks 20.3 with MinGW 17.1</p>
  <p>I have created a simple example to get a feeling for it.
  The first example (a single cpp file) works just fine.
  The second however (in a class) has build errors even though I am using the same code.</p>
  <p>I hope someone can explain the reasons why, and hopefully shows me how to solve thsi.</p>
  <p>First (working) example:</p>
  <pre><code>#include &lt;windows.h&gt;
  #include &lt;process.h&gt;
  #include &lt;iostream&gt;
  #include &lt;chrono&gt;
  #include &lt;thread&gt;
  
  struct Param
  {
      std::string param1;
  };
  unsigned Counter;
  
  unsigned __stdcall DoSomething( void *ptr )
  {
      std::cout &lt;&lt; &quot;In second thread...\n&quot;;
  
      Param *p_tmp = reinterpret_cast&lt;Param*&gt;(ptr);
      Param p_param = *p_tmp;
      std::string result = p_param.param1;
  
      while ( Counter &lt; 1000 )
      {
          Counter++;
          std::cout &lt;&lt; result &lt;&lt; Counter &lt;&lt; '\r';
          std::this_thread::sleep_for(std::chrono::milliseconds(2));
      }
      std::cout &lt;&lt; std::endl;
      _endthreadex( 0 );
  
      return 0;
  }
  
  void CreateThread()
  {
      HANDLE hThread;
      unsigned threadID;
      std::string result{&quot;Count: &quot;};
      Param param;
      param.param1 = &quot;Count: &quot;;
  
      std::cout &lt;&lt; &quot;Main thread\nCreating second thread...\n&quot;;
  
      // Create the second thread.
      hThread = (HANDLE)_beginthreadex( NULL, 0, &amp;DoSomething, (void*)&amp;param, 0, &amp;threadID );
  
      // Wait until second thread terminates
      WaitForSingleObject( hThread, INFINITE );
  
      std::cout &lt;&lt; &quot;Returned to Main thread\nCounter should be 1000; it is-&gt; &quot;&lt;&lt; Counter &lt;&lt; std::endl;
      // Destroy the thread object.
      CloseHandle( hThread );
  }
  
  int main()
  {
     CreateThread();
  }
  </code></pre>
  <p>The second example (in a class):</p>
  <pre><code>struct Param
  {
      std::string param1;
  };
  unsigned Counter;
  
  void CthreadFrame::CreateThread()
  {
      HANDLE hThread;
      unsigned threadID;
      Param param;
      param.param1 = &quot;Count: &quot;;
  
      std::cout &lt;&lt; &quot;Main thread\nCreating second thread...\n&quot;;
  
      // Create the second thread
      hThread = (HANDLE)_beginthreadex( NULL, 0, &amp;DoSomething, (void*)&amp;param, 0, &amp;threadID );
      // Wait for second thread to terminate
      WaitForSingleObject( hThread, INFINITE );
  
      std::cout &lt;&lt; &quot;Returned to Main thread\nCounter should be 1000; it is-&gt; &quot;&lt;&lt; Counter &lt;&lt; std::endl;
      // Destroy the thread object.
      CloseHandle( hThread );
  
  /* End of void CreateThread */
  }
  
  unsigned __stdcall CthreadFrame::DoSomething(void *ptr)
  {
      std::cout &lt;&lt; &quot;In second thread...\n&quot;;
  
      Param *p_tmp = reinterpret_cast&lt;Param*&gt;(ptr);
      Param p_param = *p_tmp;
      std::string result = p_param.param1;
  
      while ( Counter &lt; 1000 )
      {
          Counter++;
          std::cout &lt;&lt; result &lt;&lt; Counter &lt;&lt; '\r';
          std::this_thread::sleep_for(std::chrono::milliseconds(2));
      }
      std::cout &lt;&lt; std::endl;
      _endthreadex( 0 );
  
      return 0;
  }
  </code></pre>
  <p>Build Messages:</p>
  <pre><code>||=== Build: Debug in Cthread (compiler: GNU GCC Compiler) ===|
  F:\Data\__C++\wxApps\Cthread\CthreadMain.cpp||In member function 'void CthreadFrame::CreateThread()':|
  F:\Data\__C++\wxApps\Cthread\CthreadMain.cpp|114|error: cannot convert 'unsigned int (CthreadFrame::*)(void*)' to '_beginthreadex_proc_type' {aka 'unsigned int (*)(void*)'}|
  f:\sdks\mingw-17.1\x86_64-w64-mingw32\include\process.h|37|note:   initializing argument 3 of 'uintptr_t _beginthreadex(void*, unsigned int, _beginthreadex_proc_type, void*, unsigned int, unsigned int*)'|
  ||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 2 second(s)) ===|
  </code></pre>