Essential C++ 中的一段代码,编译通不过,帮我看一下
Asus 2001-10-25 09:10:52 下面这段是书中习题2-6的代码,我在VC6 ENTERPRISE edition 中无法通过
BCB5 中也通不过,哪位大虾看一下啦,(用VC编译标准C++好象总出奇怪的问题,
比如for(int i=0;i<10;i++)这种句子在一个函数里面i好象不会释放)
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
template <typename Type>
inline Type max(Type t1,Type t2)
{ return t1 > t2? t1: t2; }
template <typename elemType>
inline elemType max(const vector<elemType> &vec)
{ return *max_element(vec.begin(),vec.end() ); }
template <typename arrayType>
inline arrayeType max(const arrayType *parray,int size)
{ return *max_element(parray,parray+size); }
int main()
{
string sarray[]={"we","were","her","pride","of","ten"};
vector <string> svec(sarray,sarray+6);
int iarray[]={12,70,2,169,1,5,29};
vector <int> ivec(iarray,iarray+7);
float farray[]={2.5,24.8,12.1,3.4,122.23}
vector <float> fvec(farray,farray+5);
int imax=max( max(ivec),max(iarray,7) );
float fmax=max( max(fvec),max(farray,5) );
string smax=max( max(svec),max(sarray,6) );
cout<<"imax"<<imax<<endl;
cout<<"fmax"<<fmax<<endl;
cout<<"smax"<<smax<<endl;
return 0;
}