Reputation: 19903
Let's say that I've got a :
#include <utility>
using namespace std;
typedef pair<int, int> my_pair;
how do I initialize a const my_pair ?
Upvotes: 20
Views: 53870
Reputation: 154
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)};
Upvotes: 0
Reputation: 3396
With C++11 you can also use one of the following:
const my_pair p = {2, 3};
const my_pair p({2, 3});
const my_pair p{2, 3};
Upvotes: 28