This question already has an answer here:
following on from my last question: here
I have:
struct test
{
int a;
int b;
std::string str;
};
int main()
{
std::map<int, test> test_map;
test t1 = {1, 2, "hello"};
test_map[0] = t1;
return 0;
}
This works ok, but I don't really want to create a variable just to insert into the map.
Can I use uniform/aggregate initialisation to help me here, something like this:
int main()
{
std::map<int, test> test_map;
test_map[0] = {1, 2, "hello"};
return 0;
}
Aucun commentaire:
Enregistrer un commentaire