如何初始化 const std::pair?
假设我有一个:
#include <utility>
using namespace std;
typedef pair<int, int> my_pair;
如何初始化 const my_pair ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
假设我有一个:
#include <utility>
using namespace std;
typedef pair<int, int> my_pair;
如何初始化 const my_pair ?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
对于 C++11,您还可以使用以下其中一项:
With C++11 you can also use one of the following:
const my_pair p = my_pair(3, 2);
const my_pair p = my_pair(3, 2);
虽然这篇文章已经很老了,但我今天遇到了同样的问题并设法解决如下。
我希望这对其他人有帮助。
const std::array, argument_no>; infoArr = {std::make_pair("start_year", 0), std::make_pair("end_year", 0)};
Although this post is quite old, I encountered the same problem today and managed to resolve it as follows.
I hope it will be helpful for others.
const std::array<const std::pair<std::string, int>, argument_no> infoArr = {std::make_pair("start_year", 0), std::make_pair("end_year", 0)};
使用它的构造函数:
Use its constructor: