in C++11, let's say I have some code like this:
if I change the name of one of the foo() functions, it compiles without error, but if both functions are named foo, the compiler gives me the following errors:Code:template<typename Func> auto Wrapper(Func func) -> decltype(func()) { return func(); } template<typename Func, typename... Args> auto Wrapper(Func func, Args... args) -> decltype(func(args...)) { return func(args...); } void foo(int x, std::string y) { } int foo() { return 3; } void bar() { Wrapper(foo, 3, "foo"); int x = Wrapper(foo); }
is there a way to use overloaded functions with this wrapper? if so, how do I need to qualify the function names so that the compiler knows I want the one with two parameters or the one with no parameters?Code:In function 'void bar()': error: no matching function for call to 'Wrapper(<unresolved overloaded function type>, int, const char [4])' note: candidates are: note: template<class Func> decltype (func()) Wrapper(Func) note: template<class Func, class ... Args> decltype (func(Wrapper::args ...)) Wrapper(Func, Args ...) error: no matching function for call to 'Wrapper(<unresolved overloaded function type>)' note: candidates are: note: template<class Func> decltype (func()) Wrapper(Func) note: template<class Func, class ... Args> decltype (func(Wrapper::args ...)) Wrapper(Func, Args ...)



1Likes
LinkBack URL
About LinkBacks




CornedBee