Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Cannot convert from Initializer List to std::pair

Tags:

c++-cli

I have a function called TestFunction which I've simplified down for this question... but in essence, I'm getting an error which says, <function-style-cast> cannot convert from 'initializer list' to std::pair<int, int>. Here's my simplified function:

#include <iostream>
#include <map>

void MyClass::TestFunction(cli::array<int>^ ids){

    std::multimap<int, int> mymap;
    int count = ids->Length;

    for (int i = 0; i < count; ++i) {
        //fill in the multimap with the appropriate data key/values
        mymap.insert(std::make_pair((int)ids[i], (int)i));
    }
}

As you can see, it's a really basic function (when simplified), but I get an error when I try to insert the data into the multimap. Does anyone know why?

like image 695
andyopayne Avatar asked May 25 '26 03:05

andyopayne


1 Answers

I'd either use

mymap.insert(std::make_pair((int)ids[i], (int)i));

or

mymap.emplace((int)ids[i], (int)i);
like image 133
Cory Kramer Avatar answered Jun 03 '26 01:06

Cory Kramer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!