C++中Lambda表达式转化为函数指针

// -----------------------------------------------------------

auto combineCallbackLambda = [](GLdouble coords[3], void* vertex_data[4], GLfloat weight[4], void** dataOut) mutable -> void CALLBACK
{
  GLdouble * *vertex_data1 = (GLdouble * *)vertex_data;
  GLdouble* vertex = new GLdouble[7];
  vertex[0] = coords[0];
  vertex[1] = coords[1];
  vertex[2] = coords[2];
  for (int i = 3; i < 7; i++)
    vertex[i] = weight[0] * vertex_data1[0][i] + weight[1] * vertex_data1[1][i] + weight[2] * vertex_data1[2][i] + weight[3] * vertex_data1[3][i];
  *dataOut = vertex;
};

void (*combineCallbackFunction)(GLdouble coords[3], void* vertex_data[4], GLfloat weight[4], void** dataOut) = combineCallbackLambda;


// ----------------------------但[]中含有捕获时不能转换-------------------------------


auto vertexCallbackLambda = [&genPositionList, &genTriangle, &genPointIndex](void* vertex_data) mutable -> void CALLBACK
{
  fprintf(stdout, "Tessellation vertexCallback");
  GLdouble* pt = (GLdouble*)vertex_data;
  genTriangle[genPointIndex++] = pt;
  if (genPointIndex >= 3)
  {
    genPositionList.push_back(genTriangle[0]);
    genPositionList.push_back(genTriangle[1]);
    genPositionList.push_back(genTriangle[2]);
    genPointIndex = 0;
  }
};

//void (*vertexCallbackFunction)(void*) = vertexCallbackLambda;

原文链接: https://www.cnblogs.com/gispathfinder/p/10886994.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    C++中Lambda表达式转化为函数指针

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/295311

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月15日 下午4:46
下一篇 2023年2月15日 下午4:47

相关推荐