This is my code:
void Game::Music::PlayMusicThread(std::string name, std::string location, double music_len_in_seconds)
{
if (PlayingMap.count(name) == 0)
PlayingMap[name] = true;
auto start = std::chrono::system_clock::now();
PlaySound(to_wstring(location).c_str(), NULL, SND_FILENAME | SND_ASYNC);
while (PlayingMap[name])
{
if (std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now() - start).count() > music_len_in_seconds)
{
PlayMusic(name, location, music_len_in_seconds);
return;
}
}
PlayingMap.erase(name);
PlaySound(NULL, NULL, SND_FILENAME);
}
void Game::Music::PlayMusic(std::string name, std::string location, double music_len_in_seconds)
{
std::thread MusicStartThread(&Game::Music::PlayMusicThread, name, location, music_len_in_seconds);
ThreadMap[name] = &MusicStartThread;
}
And here’s the error: invoke: no matching overloaded function found
.
I have found multiple solutions to this problem on the internet, but none works. For example:
- Adding std::ref() to all the parameters;
- Adding
const type&
to the function input parameters; - Removing
Game::Music::
in thestd::thread
call.
I have heard that std::invoke doesn’t allow function pointers, but I am sure I have succeeded in it before.
1