簡體   English   中英

如何消除 C++ 中的這些線程錯誤?

[英]How do I get rid of these thread errors in C++?

我在 C++ 制作的這個程序有一些問題。對於我在這里做的事情:

{
    GridWorld world;
    string input = "";

    while (input != "q")
    {
        thread render(&GridWorld::Render, GridWorld());
        render.join();

        input = world.GetInput();

        thread thread_update(&GridWorld::Update, GridWorld());

        thread_update.join();

    }

    cout << "Thank you for playing\n";
}

我收到這些錯誤

它曾經工作過,但現在不再工作了。

有人可以幫忙嗎

您是否嘗試過使用 lambda 表達式?

...
thread render([]() { GridWorld().Render(); });
...
thread thread_update([]() { GridWorld().Update(); });
...

或者可能

...
thread render([&world]() { world.Render(); });
...
thread thread_update([&world]() { world.Update(); });
...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM