1
我正在閱讀C++ Primer第3版的章節「功能模板」,當我試圖按照該示例進行操作時,發現代碼幾乎與在VC6下編譯期間遇到錯誤的代碼相同,但一切正常在g ++下。我不知道爲什麼?關於函數模板的相同代碼塊在g ++下編譯正常,但在VC6下出錯,爲什麼?
下面是代碼:
#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;
}
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
沒有任何可靠的信息,所以沒有把答案。但它可能是VC6是可怕的老和破碎。嘗試更新的版本。 – 2012-03-05 09:44:38