title: Failed to specialize function template in threads
body: <p>I'm trying to implement a Thread in c++ wich it will be used to control when I take a picture, but this simple code is giving me a strange error, which I can't understand. This is my code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;thread&gt;
      using namespace std;
  
      void counter(int seconds, bool &amp;flagTakePhoto, bool &amp;flagThreadStart);
  
  int main() {
      bool takePhoto, threadStart;
  
      int seconds = 1;
  
      thread t(counter, seconds, takePhoto, threadStart);
      //Some code here
  }
  
  
  void counter(int seconds, bool &amp;flagTakePhoto, bool &amp;flagThreadStart) {
      while (flagThreadStart) {
          this_thread::sleep_for(chrono::seconds(seconds));
          flagTakePhoto = true;
      }
      terminate();
  }
  </code></pre>
  
  <p>This is the error:</p>
  
  <pre><code>1&gt;------ Build started: Project: Proyecto para pruebas OPENCV, Configuration: 
  Release x64 ------
  1&gt;  Main.cpp
  1&gt;Main.cpp(46): warning C4244: 'initializing': conversion from '__int64' to 'int', possible loss of data
  1&gt;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\thr/xthread(238): error C2893: Failed to specialize function template 'unknown-type std::invoke(_Callable &amp;&amp;,_Types &amp;&amp;...)'
  1&gt;  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\thr/xthread(238): note: With the following template arguments:
  1&gt;  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\thr/xthread(238): note: '_Callable=void (__cdecl *)(int,bool &amp;,bool &amp;)'
  1&gt;  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\thr/xthread(238): note: '_Types={int, bool, bool}'
  1&gt;  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\thr/xthread(247): note: see reference to function template instantiation 'void std::_LaunchPad&lt;_Target&gt;::_Execute&lt;0x00,0x01,0x02,0x03&gt;(std::tuple&lt;void (__cdecl *)(int,bool &amp;,bool &amp;),int,bool,bool&gt; &amp;,std::integer_sequence&lt;_Ty,0x00,0x01,0x02,0x03&gt;)' being compiled
  1&gt;          with
  1&gt;          [
  1&gt;              _Target=std::unique_ptr&lt;std::tuple&lt;void (__cdecl *)(int,bool &amp;,bool &amp;),int,bool,bool&gt;,std::default_delete&lt;std::tuple&lt;void (__cdecl *)(int,bool &amp;,bool &amp;),int,bool,bool&gt;&gt;&gt;,
  1&gt;              _Ty=size_t
  1&gt;          ]
  1&gt;  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\thr/xthread(247): note: see reference to function template instantiation 'void std::_LaunchPad&lt;_Target&gt;::_Execute&lt;0x00,0x01,0x02,0x03&gt;(std::tuple&lt;void (__cdecl *)(int,bool &amp;,bool &amp;),int,bool,bool&gt; &amp;,std::integer_sequence&lt;_Ty,0x00,0x01,0x02,0x03&gt;)' being compiled
  1&gt;          with
  1&gt;          [
  1&gt;              _Target=std::unique_ptr&lt;std::tuple&lt;void (__cdecl *)(int,bool &amp;,bool &amp;),int,bool,bool&gt;,std::default_delete&lt;std::tuple&lt;void (__cdecl *)(int,bool &amp;,bool &amp;),int,bool,bool&gt;&gt;&gt;,
  1&gt;              _Ty=size_t
  1&gt;          ]
  1&gt;  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\thr/xthread(242): note: while compiling class template member function 'void std::_LaunchPad&lt;_Target&gt;::_Run(std::_LaunchPad&lt;_Target&gt; *) noexcept'
  1&gt;          with
  1&gt;          [
  1&gt;              _Target=std::unique_ptr&lt;std::tuple&lt;void (__cdecl *)(int,bool &amp;,bool &amp;),int,bool,bool&gt;,std::default_delete&lt;std::tuple&lt;void (__cdecl *)(int,bool &amp;,bool &amp;),int,bool,bool&gt;&gt;&gt;
  1&gt;          ]
  1&gt;  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\thr/xthread(230): note: see reference to function template instantiation 'void std::_LaunchPad&lt;_Target&gt;::_Run(std::_LaunchPad&lt;_Target&gt; *) noexcept' being compiled
  1&gt;          with
  1&gt;          [
  1&gt;              _Target=std::unique_ptr&lt;std::tuple&lt;void (__cdecl *)(int,bool &amp;,bool &amp;),int,bool,bool&gt;,std::default_delete&lt;std::tuple&lt;void (__cdecl *)(int,bool &amp;,bool &amp;),int,bool,bool&gt;&gt;&gt;
  1&gt;          ]
  1&gt;  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\thr/xthread(256): note: see reference to class template instantiation 'std::_LaunchPad&lt;_Target&gt;' being compiled
  1&gt;          with
  1&gt;          [
  1&gt;              _Target=std::unique_ptr&lt;std::tuple&lt;void (__cdecl *)(int,bool &amp;,bool &amp;),int,bool,bool&gt;,std::default_delete&lt;std::tuple&lt;void (__cdecl *)(int,bool &amp;,bool &amp;),int,bool,bool&gt;&gt;&gt;
  1&gt;          ]
  1&gt;  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\thread(52): note: see reference to function template instantiation 'void std::_Launch&lt;std::unique_ptr&lt;std::tuple&lt;void (__cdecl *)(int,bool &amp;,bool &amp;),int,bool,bool&gt;,std::default_delete&lt;std::tuple&lt;void (__cdecl *)(int,bool &amp;,bool &amp;),int,bool,bool&gt;&gt;&gt;&gt;(_Thrd_t *,_Target &amp;&amp;)' being compiled
  1&gt;          with
  1&gt;          [
  1&gt;              _Target=std::unique_ptr&lt;std::tuple&lt;void (__cdecl *)(int,bool &amp;,bool &amp;),int,bool,bool&gt;,std::default_delete&lt;std::tuple&lt;void (__cdecl *)(int,bool &amp;,bool &amp;),int,bool,bool&gt;&gt;&gt;
  1&gt;          ]
  1&gt;  Main.cpp(136): note: see reference to function template instantiation 'std::thread::thread&lt;void(__cdecl &amp;)(int,bool &amp;,bool &amp;),int&amp;,bool&amp;,bool&amp;,void&gt;(_Fn,int &amp;,bool &amp;,bool &amp;)' being compiled
  1&gt;          with
  1&gt;          [
  1&gt;              _Fn=void (__cdecl &amp;)(int,bool &amp;,bool &amp;)
  1&gt;          ]
  ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
  </code></pre>
  
  <p>What is more strange about this is that I have a similar code in other program and compile with no errors!
  Does anyone knows what's wrong with this code?
  Thanks!</p>