c++模板函数问题
#include <iostream>using namespace std;template <class T>T max(T a,T b){ return a > b ? a : b;}int main(){ cout << max(1,2) << endl;}
1>------ 已启动生成: 项目: myproject1, 配置: Debug Win32 ------1>正在编译...1>myproject1.cpp1>d:\my documents\visual studio 2008\projects\myproject1\myproject1\myproject1.cpp(14) : error C2668: “max”: 对重载函数的调用不明确1> d:\my documents\visual studio 2008\projects\myproject1\myproject1\myproject1.cpp(7): 可能是“T max<int>(T,T)”1> with1> [1> T=int1> ]1> c:\program files\microsoft visual studio 9.0\vc\include\xutility(3356): 或 “const _Ty &std::max<int>(const _Ty &,const _Ty &)”1> with1> [1> _Ty=int1> ]1> 试图匹配参数列表“(int, int)”时1>生成日志保存在“file://d:\My Documents\Visual Studio 2008\Projects\myproject1\myproject1\Debug\BuildLog.htm”1>myproject1 - 1 个错误,0 个警告========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========