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++实现JNI接口需要注意的事项
- 关于指针的一些事情
- c++ primer 第五版 笔记前言
- share_ptr的几个注意点
- Auto Autorun.inf desktop.ini sxs.exe auto.exe类病毒的手动处理完全技巧
- auto病毒引发木马下载者病毒的完美解决方案[原创]
- C#线程间不能调用剪切板的解决方法
- Lua中调用C++函数示例
- Lua教程(一):在C++中嵌入Lua脚本
- Lua教程(二):C++和Lua相互传递数据示例
- C#线程同步的三类情景分析
- C#获取进程或线程相关信息的方法
- C#停止线程的方法
- C#子线程更新UI控件的方法实例总结
- C#线程队列用法实例分析
- C++联合体转换成C#结构的实现方法
- CSS的inherit与auto使用分析
- C++编写简单的打靶游戏
- C++ 自定义控件的移植问题
- C++变位词问题分析