I am trying to overload function with initialization_list as parameters with variation to accept map and vector along with an integer. The compiler complains that the function resolution is ambiguous. I am wondering what causes the ambiguity and how to resolve it
#include <memory>
#include <iostream>
#include <map>
#include <initializer_list>
std::shared_ptr<int> foo(const std::initializer_list<std::pair<const std::string, std::shared_ptr<int> > >& il)
{
return std::make_shared<int>();
}
std::shared_ptr<int> foo(const std::initializer_list<std::shared_ptr<int> > & il)
{
return std::make_shared<int>();
}
std::shared_ptr<int> foo(int num)
{
return std::make_shared<int>();
}
int main()
{
foo({ { "a", foo(10) } });
}
Note
- I tried with VS2013 as well as g++ and both of them errors out.
- As per @chris the above code compiles in clang
- What does the standard say? Or does it actually say anything?
Aucun commentaire:
Enregistrer un commentaire