【发布时间】:2016-05-08 10:27:08
【问题描述】:
我写了下面的代码,它给出了一个错误;
ipt.cpp:在函数‘bool isprimet(long unsigned int, int)’中: ipt.cpp:28:86: 错误: 不匹配调用 '(std::thread) (void (&)(long unsigned int, long unsigned int, long unsigned int, bool), const long unsigned int&, long unsigned int&, long unsigned int&, unsigned int&)' for (unsigned long c=0;c
我做错了什么?
#include <iostream>
#include <thread>
#include <math.h>
using namespace std;
void ipt(const unsigned long number, const unsigned long root, const unsigned long threadid, bool &result)
{
result=true;
for (unsigned long c=5+threadid*6;c<=root;c+=(threadid+1)*6)
{
if(number % c-1 == 0) {result=false; break;};
if(number % c+1 == 0) {result=false; break;};
}
}
bool isprimet(const unsigned long number, const int nthreads)
{
if (number > 1)
{
if (number > 3)
{
if (number % 2 == 0) return false;
if (number % 3 == 0) return false;
unsigned int results[nthreads];
unsigned long root=(unsigned long)floor(sqrt(number))+1;
thread t[nthreads];
for (unsigned long c=0;c<nthreads;c++) t[c](ipt, number, root, c, results[c]);
for (unsigned long c=0;c<nthreads;c++) t[c].join();
for (unsigned long c=0;c<nthreads;c++) if (results[c]==false) return false;
return true;
}
else return true;
}
else return false;
}
【问题讨论】:
标签: c++ compiler-errors