首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

C++题解为什么通不过编译

2013-10-04 
C++例题为什么通不过编译?#includeiostreamusing namespace stdtemplateclass TT max(T ml,T m2){ret

C++例题为什么通不过编译?

#include<iostream>
  using namespace std;
  template<class T>
  T max(T ml,T m2)
  {return (m1>m2)?ml:m2;}
  void main( )  {
  cout<<max(2,5)<< "\t"<<max(2.0,5.0)<<endl;
  } 

编译错误提示:
D:\Program Files\Microsoft Visual Studio\MyProjects\001\1.cpp(5) : error C2065: 'm1' : undeclared identifier
        D:\Program Files\Microsoft Visual Studio\MyProjects\001\1.cpp(7) : see reference to function template instantiation 'int __cdecl max(int,int)' being compiled
Error executing cl.exe.
是书上的例题,哪错了?
[解决办法]
#include<iostream>
  using namespace std;
  template<class T>
  T Max(T m1,T m2)
  {return (m1>m2)?m1:m2;}
  void main( )  {
  cout<<Max(2,5)<< "\t"<<Max(2.0,5.0)<<endl;
  }

热点排行