I ran into a compiler error when I tried to execute a function using std::thread. The error says : "error C2672: 'std::invoke': no matching overloaded function found".
Here is a code snippet:
void GetMinMax_X(const std::vector<Vertex>& iAllVertices, double & oMin_X,
double & oMax_X)
{
auto MinMax_X = std::minmax_element(iAllVertices.begin(),
iAllVertices.end(), [](const Vertex& i, const Vertex& j)
{
return i.GetX() < j.GetX();
});
oMin_X = MinMax_X.first->GetX();
oMax_X = MinMax_X.second->GetX();
}
int main()
{
std::vector<Vertex>;
// Some functions to fill the Vertex vector......
double Min_X = 0;
double Max_X = 0;
std::thread first (GetMinMax_X, AllVertices, Min_X, Max_X);
first.join();
return 0;
}
Thanks!
std::threadarguments are copied or moved, they cannot be references.std::refis not a reference per se, it is a reference wrapper. There is a massive difference between the two. I stand by what I said.