问题描述
std::make_pair 的目的是什么?
为什么不直接做 std::pair?
这两种方法有什么区别吗?
Is there any difference between the two methods?
推荐答案
区别在于 std::pair 需要指定两个元素的类型,而 std::make_pair 将创建一个带有传递给它的元素类型的对,而无需您告诉它.无论如何,这就是我可以从各种文档中收集到的信息.
The difference is that with std::pair you need to specify the types of both elements, whereas std::make_pair will create a pair with the type of the elements that are passed to it, without you needing to tell it. That's what I could gather from various docs anyways.
从 http://www.cplusplus.com/reference/std 中查看此示例/utility/make_pair/
pair <int,int> one;
pair <int,int> two;
one = make_pair (10,20);
two = make_pair (10.5,'A'); // ok: implicit conversion from pair<double,char>
除了它的隐式转换奖励,如果你没有使用 make_pair 你就必须这样做
Aside from the implicit conversion bonus of it, if you didn't use make_pair you'd have to do
one = pair<int,int>(10,20)
每次分配给一个,时间久了会很烦...
every time you assigned to one, which would be annoying over time...
这篇关于std::make_pair 与 std::pair 的构造函数的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)