#include <iostream>
#include <future>
class MyClass {
public:
void memberFunction(int arg) {
std::cout << "Member function called with arg: " << arg << std::endl;
}
};
int main() {
MyClass myObject;
// 使用函数对象封装类成员函数
auto memberFunctionWrapper = [&myObject](int arg) {
myObject.memberFunction(arg);
};
// 在 std::async 中传递函数对象
std::future<void> asyncFuture = std::async(std::launch::async, memberFunctionWrapper, 42);
// 等待异步任务完成
asyncFuture.wait();
return 0;
}