how use Multithread?
Feb 9, 2022 at 7:40pm UTC
i did these function:
1 2 3 4
void GetPixelImage(HDC HDCOrigin, int PosX, int PosY, COLORREF &color)
{
color=::GetPixel(HDCOrigin, PosX, PosY);
}
heres how i use it:
1 2 3
COLORREF color;
std::thread thread_obj(GetPixelImage, HDCOrigin,PosY+800,PosX,color);
thread_obj.join();
why i get these error?
"error: no matching function for call to 'std::thread::_Invoker<std::tuple<void (*)(HDC__*, int, int, long unsigned int&), HDC__*, int, int, long unsigned int> >::_M_invoke(std::thread::_Invoker<std::tuple<void (*)(HDC__*, int, int, long unsigned int&), HDC__*, int, int, long unsigned int> >::_Indices)'|"
Feb 9, 2022 at 11:11pm UTC
Try
std::ref(color)
instead of just color. #include <functional> as well.
You can't pass references to the thread object like that. JLBorges once showed me a workaround. Here's an example with an int ref:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
// Example program
#include <iostream>
#include <thread>
#include <functional> // std::ref
void GetPixelImage(int copy, int & ref)
{
ref = 42;
}
int main()
{
int beans = 3;
int my_int = 17;
std::thread thread_obj(GetPixelImage, beans, std::ref(my_int));
thread_obj.join();
std::cout << my_int << '\n' ;
}
See also:
https://stackoverflow.com/questions/34078208/passing-object-by-reference-to-stdthread-in-c11/
Feb 10, 2022 at 5:52am UTC
This is also the case with (the bind expression created by)
std::bind
Topic archived. No new replies allowed.