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;
}
}
}