具有类成员功能的std :: async
std::async with class member function
我是std::async
的新手,我有问题了解它的工作原理。我看到了如何将成员功能传递到网络某个地方的std::async
的示例,但似乎没有编译。这里有什么问题?没有Lambda,该怎么办?
class Test {
std::future<void> f;
void test() {}
void runTest() {
// ERROR no instance overloaded matches argument list
f = std::async(std::launch::async, &Test::test, this);
// OK...
f = std::async(std::launch::async, [this] {test();});
}
void testRes() {
f.get();
}
};
f = std::async(std::launch::async, std::bind(&Test::test, this));
在您的示例中&amp; test :: test并不是std::async
所期望的Test
类型参数的函数。相反,它是成员函数,必须以不同的方式调用。
相关文章:
- 为什么std::async使用同一个线程运行函数
- 为什么可以将左值传递给"std::async",即使它引用了右值
- 使用 std::async 时死锁,将来作为成员
- 为什么我不能将引用作为 std::async 的函数参数传递
- std::async from std::async in windows xp
- std::async 如何工作:为什么它会调用这么多次复制/移动?
- std::async 不会立即调用
- std::async 如果线程是从 DLL 创建的,则会阻止进程退出?
- 可能的 std::async 实现错误 Windows
- C++从 std::async 函数读取命名空间中的全局变量标志
- std::async 究竟是如何执行的?
- 使用 g++8 和 c++20 的 std::async 编译问题
- 如何有效地使用 std::async 对指针数组执行操作
- 如何从 std::async 任务返回 std::tuple
- 使用 std::bind 将 QTimer::singleShot 传递给 std::async
- 如何将函数及其参数传递给成员函数内的 std::async
- 从 VS2013 到 VS2017 std::async 不会启动新线程
- 使用 std::async 调用模板函数的正确方法是什么?
- C++ - 使用 std::async 时显示进度条
- Clang 崩溃,在 std::async 中出现字符 * 异常