您的位置:首页 > 编程语言 > C语言/C++

c++11使用 async异步函数并传递参数以及auto的使用方法

2015-11-26 21:07 816 查看
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;



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c++ c++11 线程 auto