无法专门化函数模板<unknown-type std :: invoke(_callable =“”&& _ types && =“”> noexept(<expr>)

时间:2018-05-01 00:52:54

标签: c++ multithreading

在评论出与线程相关的所有行后,错误就消失了。

  

无法专门化函数模板:unknown-type std :: invoke(_callable&amp;&amp; _Types&amp;&amp; noexept(expr)

     

std :: invoke:找不到匹配的重载函数

int main()
{
vector<Bunny*> bunny;

for (int i = 0; i < 5; i++) bunny.push_back(new Bunny(random(20) + 20, 
random(3) + 1, random(2), 0));

thread updater(UpdateTotals, bunny);

for (;;)    
{

 //Nothing here yet

}

exiting = 1;
updater.join();
cin.get();
}

bool exiting = 0;

UpdateTotals 功能(取向量参数) 线程将无限循环遍历此函数,直到退出主循环。

void UpdateTotals(vector<Bunny*>& bun)
{

for (;;)
{

    for (int i = 0; i < bun.size(); i++)
    {
        if (bun[i]->isAlive() && !bun[i]->checked) {
            bun[i]->checked = 1;
            ++total::bunnies;

            switch (bun[i]->color)
            {
            case ref::white: ++total::color[ref::white];

                break;
            case ref::brown: ++total::color[ref::brown];

                break;
            case ref::black: ++total::color[ref::black];

            }

            if (bun[i]->gender == 'm') {
                ++total::gender[0];

            }
            else {
                ++total::gender[1];

            }

            if (bun[i]->mutant) {
                ++total::mutants;

            }


        }
        else if (!bun[i]->isAlive() && !bun[i]->checked)
        {
            if (bun[i]->gender == 'm') --total::gender[0];
            else --total::gender[1];

            if (bun[i]->mutant) --total::mutants;

            if (bun[i]->color == ref::black) --total::color[ref::black];
            else if (bun[i]->color == ref::brown) -- 
 total::color[ref::brown];
            else --total::color[ref::white];

            delete bun[i];
            bun.erase(bun.begin() + i);
            --total::bunnies;
        }
        this_thread::sleep_for(10ms);
    }
    if (exiting) break;
}

0 个答案:

没有答案