利用VC++6.0进行STL模板测试泛型函数中max()和min()报错
测试:
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
cout<<max(3,4)<<endl;
cout<<min(19,33)<<endl;
return 0;
}
结果报错:
error C2065: 'max' : undeclared identifier
error C2065: 'min' : undeclared identifier
解决办法:
vc6.0中,默认将max()修改成了_cpp_max(),min()同理,因此当我们按max()编写时便报错,逆向思维那么我们只要把max()和min()改为_cpp_max()和_cpp_min()就行
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
cout<<_cpp_max(3,4)<<endl;
cout<<_cpp_min(19,33)<<endl;
return 0;
}
输出结果:
4
19
Press any key to continue