I am using C++ 03, previously I have code:
static const std::vector<std::pair<uint16_t, uint16_t>> a = boost::assign::list_of(std::make_pair(1,1)) std::make_pair(2,2));
and it worked.
Now I need to add an If block and in different cases a needs to be different values, so I have:
static const std::vector<std::pair<uint16_t, uint16_t>> a;
if (xxx){
a = boost::assign::list_of(std::make_pair(1,1)) std::make_pair(2,2));
}
else{
a = boost::assign::list_of(std::make_pair(1,1)) std::make_pair(3,3));
}
and I got error:ambiguious overload for operator= ..........
how can I fix it?
If you look closer at your error message you'll probably find mention of not being able to convert to
const. Asaisconstyou can't assign to it. You need to either makeanon-constor you need to initialise it on assignment. You can do this either with a ternary:Or by using a function: