I have a function
int f(std::shared_ptr<MyClass> sptr);
After that, I write the following template to be able to call it (and some other) functions:
template <typename Func, typename ArgType> auto call(Func func, ArgType arg) -> decltype(func(arg)) { return func(arg); }
Why am I getting an error in the third line when I try to use this template with NULL?
auto r0 = f(0); // OK auto r1 = call(f, nullptr); // OK auto r2 = call(f, NULL); // ERROR! WHY?? 1>------ Build started: Project: ConsoleApplication1, Configuration: Debug x64 ------ 1> main.cpp 1>main.cpp(245): error C2893: Failed to specialize function template 'unknown-type call(Func,Arg)' 1> With the following template arguments: 1> 'Func=int (__cdecl *)(std::shared_ptr<MyClass>)' 1> 'Arg=int' ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
source share