17

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 ?

Soo Wei Tan
  • 3,262
  • 2
  • 34
  • 36
Maciek
  • 19,435
  • 18
  • 63
  • 87

4 Answers4

35

Use its constructor:

const my_pair p( 1, 2 );
26

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};
19
const my_pair p = std::make_pair( 2, 3);
Cătălin Pitiș
  • 14,123
  • 2
  • 39
  • 62
1

const my_pair p = my_pair(3, 2);

Ivan
  • 1,735
  • 1
  • 17
  • 26