gpt4 book ai didi

c++ - 为什么我必须使用std::make_pair?

转载 作者:行者123 更新时间:2023-12-02 10:07:55 26 4
gpt4 key购买 nike

我已经用过typedef

typedef std::pair<int, int> coords;
typedef std::pair<float, coords> fcoords;

然后创建此数据类型的 vector
std::vector<fcoords> openList;

因此,当我尝试向 vector 添加元素时,为什么必须使用make_pair进行处理
int i = _start.first;
int j = _start.second;
openList.push_back(std::make_pair(0.0, std::make_pair(i, j)));

为什么不能仅通过添加值来做到这一点?
openList.push_back(0.0f, (i, j));

最佳答案

您可以使用:

openList.push_back({0.0f, {i, j}});

关于c++ - 为什么我必须使用std::make_pair?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59254593/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com