————————————————
版权声明:本文为CSDN博主「未来的老公」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_35107322/article/details/107811502
make_pair用来拼接2个参数,合并为1个,不能再多了
可以用来接收两个返回值,如果有多个返回值,可以直接拼接到struct里面返回。
#include <iostream> // for make_pair
#include <memory> // for shared_ptr
using namespace std;
namespace nm_test_pair{
std::shared_ptr<std::pair<int, char> > test_func(int v1, char v2){
return std::make_shared<std::pair<int, char> >(std::make_pair(v1, v2));
}
void test(){
std::shared_ptr<std::pair<int, char> > result = test_func(1, 'a');
if(result){
cout<<result->first<<endl;
cout<<result->second<<endl;
}
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
</div><div><div></div></div>
<link href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/markdown_views-d7a94ec6ab.css" rel="stylesheet">
<link href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/style-49037e4d27.css" rel="stylesheet">
</div>
</article>