title: Constructing a std::thread with a function
body: <p>This works:</p>
  
  <pre><code>    std::thread t = std::thread(printf, "%d", 1);
  </code></pre>
  
  <p>This doesn't work:</p>
  
  <pre><code>t2 = std::thread(my_thread_func , std::ref(context));
  </code></pre>
  
  <p>OR</p>
  
  <pre><code>std::thread t1 = std::thread(my_thread_func , context_add);
  </code></pre>
  
  <p>my_thread_func definition : </p>
  
  <pre><code>int my_thread_func(long long *context_add)
  </code></pre>
  
  <p>context is some struct .. and I'm trying to do 'pass by reference'</p>
  
  <p>Error:</p>
  
  <pre><code>function call missing argument list;
  
  error C2661: 'std::thread::thread' : no overloaded function takes 2 arguments
  </code></pre>
  
  <p><em>>>> EDIT &lt;&lt;&lt;</em></p>
  
  <p>Sorry for confusion ... actually I'm defining my_thread_func in public of MainPage, so I cannot use native type hence I thought worth trying for long and give it address.</p>
  
  <pre><code>/* test data types, context for thread function, in .cpp (not in namespace) */
  typedef struct _test_context
  {
      HANDLE hHandle;
      unsigned int flag;
  }test_context_t;
  
  test_context_t *context;
  //Do something with its member
  context_add = (long long *)context;
  std::thread t2 = std::thread(sem_waiting_thread, context_add);
  </code></pre>
  
  <p>ERROR:</p>
  
  <pre><code>error C3867: 'App1::MainPage::my_thread_func': function call missing argument list; use '&amp;App1::MainPage::my_thread_func' to create a pointer to member
  error C2661: 'std::thread::thread' : no overloaded function takes 2 arguments
  </code></pre>
  
  <p>my namespace looks like:</p>
  
  <pre><code>namespace App1
  {
      public ref class MainPage sealed
      {
     public:
      MainPage();
         public:
             MainPage();
             int my_thread_func(long long cotext);
        ..
      };
  }
  </code></pre>
  
  <p><em>&lt;&lt;&lt;&lt; EDIT 2 >>></em>
  I'm curious now .. this simple one also doesn't work!</p>
  
  <pre><code>void f1(int n)
  {
      for(int i=0; i&lt;5; ++i) {
          // Print n
          std::this_thread::sleep_for(std::chrono::milliseconds(10));
      }
  } 
  .
  .
  .
  
  int n=0;
  std::thread t2(f1, n+1); (//This didn't work,same error!)
  
  .
  .
  .
  but this worked!
  std::thread t2;
  .
  .
  .
  t2= std::thread (f1, n+1);
  </code></pre>
  
  <p>Trying from here: <a href="http://en.cppreference.com/w/cpp/thread/thread/thread" rel="nofollow">http://en.cppreference.com/w/cpp/thread/thread/thread</a></p>