In the code below I have a problem trying to run a thread using function overload. It's like std::thread
does not understand overhead.
Noinstanceoftheconstructor"std :: thread :: thread" matches the list of arguments.
Does anyone know how to solve this problem?
#include "stdafx.h"
#include <Windows.h>
#include <thread>
#pragma region HotkeysComands
void HotkeysComand() {
printf("Comando executado apenas uma vez.\n");
}
#pragma endregion
#pragma region Hotkeys
void HotkeyPress(int vKey, void(*pFuncao)()) {
BOOL CheckPress;
while (true) {
if (GetAsyncKeyState(vKey) < 0) {
if (CheckPress == TRUE) {
CheckPress = FALSE;
pFuncao();
}
}
else
{
CheckPress = TRUE;
}
}
}
void HotkeyPress(int vKey, int vKey2, void(*pFuncao)()) {
BOOL CheckPress;
while (true) {
if (GetAsyncKeyState(vKey) < 0 && GetAsyncKeyState(vKey2) < 0) {
if (CheckPress == TRUE) {
CheckPress = FALSE;
pFuncao();
}
}
else
{
CheckPress = TRUE;
}
}
}
void HotkeyPressThread(int vKey, void(*pFuncao)()) {
std::thread t1(HotkeyPress, vKey, pFuncao); // Executa Thread
t1.detach(); // desanexar t1 do thread principal
}
void HotkeyPressThread(int vKey, int vKey2, void(*pFuncao)()) {
std::thread t2(HotkeyPress, vKey, vKey2, pFuncao); // Executa Thread
t2.detach(); // desanexar t1 do thread principal
}
#pragma endregion
int main()
{
HotkeyPressThread(VK_F2, HotkeysComand);
HotkeyPressThread(VK_SHIFT, VK_F1, HotkeysComand);
while (true) {
printf("Primeira Thread\n");
Sleep(1000);
}
getchar();
return 0;
}