4

I want to insert an integer value and a pair in a multiset.

So I declared it as:

multiset < int, pair < int, int> > mp;
int m,n,p;

To insert in multiset I tried this :

mp.insert(make_pair(m, make_pair(n,p))); // Compile time error

But its giving compile time error... Could someone please suggest the correct method to implement it.

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Rishabh
  • 730
  • 2
  • 11
  • 25

1 Answers1

7

The type multiset<int,pair<int,int>> is trying to create a multiset where the Key is int and the Compare is pair<int,int>. This is nonsensical. You either want to use

multiset<pair<int,pair<int,int>>>

or you want to use

multiset<tuple<int,int,int>>

The former type (pair<int,pair<int,int>>) matches the expression you're using to insert into the set (make_pair(m, make_pair(n,p))). If you use the latter, you'll want make_tuple(m,n,p).

Lily Ballard
  • 182,031
  • 33
  • 381
  • 347
  • thanks for the answer,somehow it was working for multimap but fails in case of multiset, could you please suggest some possible reasons ? – Rishabh Oct 04 '12 at 19:38
  • 2
    @rishabh : `multimap` has a key and a value, `multiset` only has a key. What are you trying to accomplish? It's hard to help when you show nonsense code and don't explain the goal. ;-] – ildjarn Oct 04 '12 at 19:44
  • @ildjarn thanks for the clarification,i am new to these concepts so I should better study them in greater detail before asking any further question... – Rishabh Oct 04 '12 at 19:49