Meh*_*dad 2 c++ templates visual-c++
为什么编译器无法找出这些模板参数?有没有办法让它这样做?
(我正在使用Visual Studio 2010.)
template<typename T, typename TFunc>
void call(TFunc func) { func(T()); }
void myfunc(void *) { }
int main() { call(myfunc); }
Run Code Online (Sandbox Code Playgroud)
Jam*_*lis 11
T在参数列表T中没有出现,因此无法从函数参数中推断出来.要推导的所有类型必须出现在参数列表中的推导上下文中.例如,
template <typename TReturn, typename TParameter>
void call(TReturn (*f)(TParameter))
{
f(TParameter());
}
Run Code Online (Sandbox Code Playgroud)