关于函数模板的相同代码块在g++下编译正常,但在VC6下编译错误,原因是什么
Same code blocks about function template compiled ok under g++ but error under VC6, why?
我正在阅读C++Primer第三版的"函数模板"一章,当我试图遵循这个例子时,我发现代码几乎与本书相同。在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;
}
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是一个古老的编译器,其对模板的支持严重不足,因此在许多情况下无法处理合法代码。你应该放弃它,转而下载VS 2010 Express。
相关文章:
- 断言中的Fold表达式在某些计算机上编译,但在其他计算机上不编译
- 编译在我的 Mac 上工作,但在集群 (Linux) 上不起作用
- 我编写了代码将十进制分数转换为其二进制等效数.它编译得很好,但在执行时挂起
- 在Visual Studio中使用括号时编译错误,但在G ++ / CLang ++中传递
- std::to_chars在MacOS/clang上编译但不链接
- 带有引用的std::tuple在clang中编译失败,但在gcc中编译失败
- 返回实例变量的c++方法可以访问变量中的数据,但不能更改它,但在编译时不会生成错误
- 我有一个C++函数,它在Dev C++中编译,但在G++中不编译
- Lua :在原生lua中编译,但在使用LuaJIT和sol2时C++出错
- 分配给静态变量的局部变量;编译错误在'c'但在 C++ 中成功
- 运行程序时找不到共享对象库,但在编译过程中链接了它
- C++代码编译,但在 Zorin OS 上运行时显示错误
- 我正在尝试使用回溯来解决 N queen 问题,但在编译时它会给出运行时错误(动态堆栈缓冲区溢出)
- Cmake Mac OSX库链接问题:在Linux上进行编译,但在Mac上进行了编译
- cmake cuda在Windows上单独的编译静态LIB链接错误,但在Ubuntu上没有
- strcpy 在 Windows 上编译,但在 Linux 上不编译
- 在 Windows 上编译错误 C2131 和 C3863,但在 Linux 上不编译错误
- 相同的代码在 Dev C++ 上编译,但在 Visual Studio 2017 上不编译
- 从std::map派生的类不在Visual C++上编译(但在gcc和clang上编译)
- 在 Xcode 6 中运行 cpp-netlib - 编译但在运行时崩溃