title: Passing pointer as argument with std::thread function C++11
body: <p>I wanted to pass a pointer to the thread function, but it gives back </p>
  
  <blockquote>
    <p>error: 
          attempt to use a deleted function
        __invoke(_VSTD::move(_VSTD::get&lt;0>(__t)), _VSTD::move(_VSTD::get&lt;_In...</p>
  </blockquote>
  
  <p>Code fragment in main</p>
  
  <pre><code>for (int i = 0; i &lt; threadCount; ++i) {
      ptrTabThreads = new std::thread(checkMin, ptrTab[i]);
      ptrTabThreads-&gt;join();
      ++ptrTabThreads;
  }
  </code></pre>
  
  <p>And code for checkMin function</p>
  
  <pre><code>void checkMin(int* tab) {
      int sizeOfTable = 0;
  
      if (tab == ptrTab[threadCount-1])
          sizeOfTable = partSize + additionalNumbers;
      else
          sizeOfTable = partSize;       
  
      mt.lock();
      for (int i = 0; i &lt; sizeOfTable; ++i) {
          if (tab[i] &lt; minValue) {
              minValue = tab[i];
          }
      }
      mt.unlock(); 
  }
  </code></pre>
  
  <p>Where ptrTab is an array of pointers:</p>
  
  <pre><code>int* ptrTab[threadCount];
  </code></pre>
  
  <p>Full code is:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;thread&gt;
  #include &lt;condition_variable&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;climits&gt;
  
  #define threadCount 10
  #define numbersCount 75
  std::mutex mt;
  int minValue = INT32_MAX;
  int partSize, additionalNumbers;
  int* ptrTab[threadCount];
  
  void checkMin(int value);
  void printTab(int *tab);
  
  int main() {
      int tab[numbersCount];
      srand(time(NULL));
  
      for (int i = 0; i &lt; numbersCount; ++i) {
          tab[i] = rand() % 1000;
          std::cout &lt;&lt; " " &lt;&lt; tab[i];
      }
  
      partSize = numbersCount / threadCount;
      additionalNumbers = numbersCount % threadCount;
  
      for (int i = 0; i &lt; threadCount-1; ++i) {
          int *newTab = new int[partSize];
          ptrTab[i] = newTab;
      }
      int *newTab = new int[partSize+additionalNumbers];
      ptrTab[threadCount-1] = newTab;
  
      int copiedElements = 0;
      for (int i = 0; i &lt; threadCount-1; ++i) {
          int *tmpTab = ptrTab[i];
          for (int j = 0; j &lt; partSize; j++) {
              tmpTab[j] = tab[copiedElements];
              copiedElements++;
          }
      }
      int *tmpTab = ptrTab[threadCount-1];
      int elementsLeft = numbersCount-copiedElements;
      for (int i = 0; i &lt; elementsLeft; ++i) {
          tmpTab[i] = tab[copiedElements];
          copiedElements++;
      }
  
      /*for (int i = 0; i &lt; threadCount; ++i) {
          printTab(ptrTab[i]);
      }*/
  
  
      //----------------------
  
      std::thread tabThreads[threadCount];
      std::thread *ptrTabThreads = tabThreads;
  
      for (int i = 0; i &lt; threadCount; ++i) {
          ptrTabThreads = new std::thread(checkMin, ptrTab[i]);
          ptrTabThreads-&gt;join();
          ++ptrTabThreads;
      }
  
      std::cout &lt;&lt; "\n\n" &lt;&lt; minValue &lt;&lt; "\n\n";
  
      //for check
      std::cout &lt;&lt; "for check: minimal value is ";
      int min = INT32_MAX;
      for (int i = 0; i &lt; numbersCount; ++i) {
          if (tab[i] &lt; min) {
              min = tab[i];
          }
      }
      std::cout &lt;&lt; min &lt;&lt; "\n\n";
  
  }
  
  void checkMin(int* tab) {
      int sizeOfTable = 0;
  
      if (tab == ptrTab[threadCount-1]) 
          sizeOfTable = partSize + additionalNumbers;
      else
          sizeOfTable = partSize;        
  
      mt.lock();
      for (int i = 0; i &lt; sizeOfTable; ++i) {
          if (tab[i] &lt; minValue) {
              minValue = tab[i];
          }
      }
      mt.unlock();
  }
  
  void printTab(int *tab) {
      for (int i = 0; i &lt; 10; ++i) {
          std::cout &lt;&lt; tab[i] &lt;&lt; " ";
      }
      std::cout &lt;&lt; "\n\n";
  }
  </code></pre>
  
  <p>Thank you for all your advices.</p>