c++ - Why is this call of overloaded function ambiguous? -
why constructor call ambiguous?
#include <functional> class { std::function<int(void)> f_; std::function<float(void)> g_; public: a(std::function<int(void)> f) { f_ = f; } a(std::function<float(void)> g) { g_ = g; } ~a() {} }; int main() { a([](){ return (int)1; }); return 0; } note typecast.
is there way tell compiler constructor overload use?
it's defect in standard. see dr 2132:
consider following:
#include <functional> void f(std::function<void()>) {} void f(std::function<void(int)>) {} int main() { f([]{}); f([](int){}); }the calls f in main ambiguous. apparently because conversion sequences
std::functionlambdas identical. standard specifies function object givenstd::function"shall callable (20.8.11.2) argument typesargtypes, return typer." doesn't if not case, constructor isn't part of overload set.
try using function pointer argument instead:
a(int f()) { f_ = f; } a(float g()) { g_ = g; }
Comments
Post a Comment