class X
{
public:
int foo(int a,std::string const& b){std::cout<<a<<std::endl<<b<<std::endl;return 3;}
std::string bar(std::string const& a){std::cout<<a<<std::endl;return a;}
};
<pre name="code" class="cpp"> X x;
//传入x是传入x的副本
auto f1 = std::async(&X::foo,x,1,"hello");
//传入&x\std::ref(x)是传入x的引用
//std::future<int> f2 = std::async(&X::bar,&x,"hi");
auto f2 = std::async(&X::bar,&x,"hi");
auto f3 = std::async(&X::bar,std::ref(x),"hi");
std::cout<<f2.get()<<std::endl;
std::cout<<f1.get()<<std::endl;
std::cout<<f3.get()<<std::endl;