我有一个功能
int f(std::shared_ptr<MyClass> sptr);
template <typename Func,typename ArgType> auto call(Func func,ArgType arg) -> decltype(func(arg)) { return func(arg); }
当我尝试将此模板与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 ==========