title: call_once to initialize a function
body: <p>I am trying to initialize a function using call_once(...). My program is giving me the compiling error 'std::once_flag::once_flag(const std::once_flag&amp;)': attempting to reference a deleted function. I don't understand why the function is deleted.</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;string&gt;
  #include &lt;thread&gt;
  #include &lt;future&gt;
  #include &lt;cstdio&gt;
  #include &lt;iostream&gt;
  #include &lt;queue&gt;
  #include &lt;condition_variable&gt;
  
  using namespace std;
  
  
  once_flag flagZero;
  
  string printerFunc(queue&lt;char&gt;&amp; input, once_flag&amp; flag){
      string output = "";
      function&lt;void(string&amp;)&gt; f;
      call_once(flag, [&amp;](){
          f = [&amp;](string&amp; output){}; });
      f(output);
      return output;
  }
  
  int _tmain(int argc, _TCHAR* argv[])
  {
       string input = "0102030";
       queue&lt;char&gt; inputQueue;
       for(char c : input){
           inputQueue.push(c);
       }
       auto zeros = async(printerFunc, ref(inputQueue), flagZero);
  
       this_thread::sleep_for(chrono::seconds(10));
      return 0;
  }
  </code></pre>