I was trying to create a pair of id and object like this:
#include <iostream>
#include <utility>
#include <functional>
struct num{
double x;
double y;
};
int main(){
auto tmp = std::make_pair(1, {1.0, 2.0});
}
I get error as error: no matching function for call to 'make_pair(int, <brace-enclosed initializer list>)'
Is there a proper way to create pair of id and object?
No, This is how you should create your pair:
auto tmp = std::make_pair(1, num{1.0, 2.0});
Or alternatively (as @StoryTeller mentioned):
std::pair<int,num> tmp {1, {1.0, 2.0}};
Now, in both cases, the compiler has a clue that {1.0, 2.0}
is meant to be an initializer for the num
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With