简体   繁体   中英

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

I'm having some problems with this program I'm making in C++. For what I'm doing here:

{
    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";
}

I get these errors

It used to work before, but now it is not anymore.

Can someone please help

Have you tried using lambda expressions?

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

Or maybe

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM