c++ - C ++,使用模板调用成员函数上的线程
问题描述
我想在这些成员函数上调用线程(它们采用完全相同的参数)。请注意,这 ALL 发生在一个名为 Renderer 的类中。
template <class Pixel>
void DrawFlatBottom(Pixel& leftPixel, Vec2& leftScreen, Pixel& topPixel, Vec2& topScreen, Pixel& rightPixel, Vec2& rightScreen, Vec4 (*PixelShader)(Pixel& sd)) {
// DrawFlatBottom implementation
}
template <class Pixel>
void DrawFlatTop(Pixel& leftPixel, Vec2& leftScreen, Pixel& bottomPixel, Vec2& bottomScreen, Pixel& rightPixel, Vec2& rightScreen, Vec4 (*PixelShader)(Pixel& sd)) {
// DrawFlatTop implementation
}
这是我尝试调用线程的方式:
template <class Pixel>
void DrawTriangle(Pixel p1, Pixel p2, Pixel p3, Vec4 (*PixelShader)(Pixel& sd)) {
std::thread flatBottom(&Renderer::DrawFlatBottom<Pixel>, std::ref(*middlePixel), std::ref(*middleScreen), std::ref(*topPixel), std::ref(*topScreen), std::ref(cutPixel), std::ref(cutScreen), PixelShader);
std::thread flatTop(&Renderer::DrawFlatTop<Pixel>, std::ref(*middlePixel), std::ref(*middleScreen), std::ref(*bottomPixel), std::ref(*bottomScreen), std::ref(cutPixel), std::ref(cutScreen), PixelShader);
// rest of DrawTriangle implementation
}
请注意,这些调用本身是在模板化函数中,其模板参数 Pixel 被传递到另一个模板化函数(DrawFlatBottom 和 DrawFlatTop)
但是,这会导致编译错误
Error C2672 'std::invoke': no matching overloaded function found
Error C2893 Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...) noexcept(<expr>)'
我认为我传递的所有参数都是正确的(即:它们都是正确的类型)。也许我错误地传递了 PixelShader 函数指针(最后一个参数)。我很确定它一定与模板有关。
解决方案
推荐阅读
- java - 编解码器和 mp4 文件的简陋视频 (Xuggle) 问题
- ssl - OpenSSL 证书:作曲家安装的自签名证书
- reactjs - 如何将事件侦听器添加到 create-react-app 默认 sw.js 文件
- javascript - 模态关闭时停止视频 - Plyr 插件
- api - 如何在 ApiResource 中使用 PUT 和 DELETE?
- react-native - 反应本机没有接收到带有套接字 io 的连接回调
- wcf - 用于 HTTPS 与 HTTP 的 IIS 的 WCF 绑定问题 绑定实例已关联以进行侦听
- html - 如何为图像的 css-border 分配动态颜色?
- python - 使用 Celery 对用户执行定期任务或使用 Celery Beat 迭代所有用户
- php - JSONArray 未显示在回收站视图中