我假设我缺少一些非常简单的东西std::async。我正在尝试void异步运行 2 个方法,没有返回值。
#include <future>
class AsyncTestClass {
public:
void Initialize()
{
std::async(&AsyncTestClass::AsyncMethod1);
std::async(&AsyncTestClass::AsyncMethod2);
}
void AsyncMethod1()
{
//time consuming operation
}
void AsyncMethod2()
{
//time consuming operation
}
};
但是在调用 my AsyncMethod1or AsyncMethod2within时会出错std:async:
替换失败:type 'typename std:conditional<sizeof....(ArgTypes) == 0, std::_Invoke_traits_Zero<void, typename std::decay .....is ill forms with _Fty = void (AsyncTestClass:: *)(), _ArgTypes =
std:async无void参数方法的正确用法是什么?我看到的示例似乎与我使用它的方式相似,但它对我不起作用。