0

I've a few singelton classes, and in the main function I try to run them as thread. But I did not found a solution, to do this.

#pragma once

class Game
{
private:
    Game() {}
public:
    static Game& getInstance()
    {
        static Game instance;
        return instance;
    }
};

and I init them like this:

int main()
{
        Game game = Gane::getInstance();

        std::thread game_thread(&game.checkStatus, game);
        game_thread.join();

        while (true){}
    

I try to run threads in the main function but it wont work:

std::thread game_thread(game.checkStatus);

But I can call the function with the dot syntax only, which is not working for threading. I got the following error: a pointer to a bound function may only be used to call the function

If i try it like this, VS Code is not compiling it:

std::thread player_thread(&Player::obtainPlayers);

and give me following error: std::Invoke, No matching overloaded function found Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&…) noexcept()'

any ideas how to run threads with dotted syntax, since I cant use pointer(->) or static(::) syntax there because of singelton and static return?

I've searched in other topics and nothing worked.

Ayoi
  • 1
  • 2

0 Answers0