7

I am trying to use a multimap with an integer key and values made of array of integers with 2 elements.

typedef std::multimap<int,int[2]> reverseHeightMap;
reverseHeightMap container;

When I try to add values like this:

container.insert( std::pair<int,int[2]>(5,{1,2}) );

I get:

error C2143: syntax error: missing ')' before '{'

I can't figure if I am failing at defining the data structure or inserting the value, or both. Thanks in advance for the help :)

Andrea Casaccia
  • 4,802
  • 4
  • 29
  • 54

2 Answers2

8

You can't store arrays in containers because one of the requirements for the datatypes stored in STL containers is that they are assignable; arrays are not assignable.

Consider using std::vector or std::array<int, 2>.

Seth Carnegie
  • 73,875
  • 22
  • 181
  • 249
5

use std::pair:

typedef std::multimap<int,std::pair<int,int>> reverseHeightMap;

OR :

encapsulate int[2] in struct :

struct int_2
{
    int i_0;
    int i_1;
};

typedef std::multimap<int,int_2> reverseHeightMap;
isolat
  • 51
  • 1
  • 1