Ori*_*ood 1 c++ function-templates
我正在阅读C++ Primer第3版的 "功能模板"一章,当我试图按照这个例子时,我发现代码几乎与本书在VC6下编译时遇到错误相同但在g ++下一切正常.我不知道为什么?
这是代码:
#include <iostream>
using namespace std;
template<typename T1, typename T2, typename T3>
T1 my_min(T2 a, T3 b)
{
return a>b?b:a;
}
int main()
{
int (*fp)(int, int) = &my_min<int>;
cout<<fp(3,5)<<endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
发生的错误VC6如下所示:
error C2440: 'initializing' : cannot convert from '' to 'int (__cdecl *)(int,int)'
None of the functions with this name in scope match the target type
Run Code Online (Sandbox Code Playgroud)