米奇鱼一次生多少小鱼:c++求助!!关于函数的

来源:百度文库 编辑:高校问答 时间:2024/04/30 01:08:39
我刚学了没多久,对c++还很模糊,先谢谢各位大侠了
在vc中编译的
#include<iostream.h>
template<class T>;
T maximum(T value1,T value2,T value3)
{

T max=value1;
if(value2>max)
max=value2;

if(value3>max)
max=value3;
return max;
}
int main()
{
int int1,int2,int3;
cout<<"输入3个integer: ";
cin>>int1>>int2>>int3;
cout<<"3个int型变量的结果是:"<<maximum(int1,int2,int3)<<endl;

float float1,float2,float3;
cout<<"输入3个单精度数:";
cin>>float1>>float2>>float3;
cou<<"3个float的结果:"<<maximum(float1,float2.float3)<<endl;
return 0;

}

error C2059: syntax error : '<end Parse>'
error C2143: syntax error : missing ';' before '{'
error C2447: missing function header (old-style formal list?)
error C2065: 'int1' : undeclared identifier
error C2065: 'int2' : undeclared identifier
error C2065: 'int3' : undeclared identifier
error C2065: 'maximum' : undeclared identifier
error C2065: 'float1' : undeclared identifier
error C2065: 'float2' : undeclared identifier
error C2065: 'float3' : undeclared identifier
error C2065: 'cou' : undeclared identifier
error C2297: '<<' : illegal, right operand has type 'char [17]'
error C2228: left of '.float3' must have class/struct/union type
Error executing cl.exe.

88.obj - 13 error(s), 0 warning(s)

感觉是上面的有问题,不过按着教程抄的,
不明白。。。
定义模板比我少了一个";"
呵呵,是不是阿,哈哈?

第2行多一个“;”
24行cout少个“t”,float3前面是","而不是“.”

看看我的就知道了
#include<iostream.h>
template <class T>
T maximum(T value1,T value2,T value3)
{ T max=value1;
if(value2>max)
max=value2;

if(value3>max)
max=value3;
return max;
}
int main()
{
int int1, int2, int3;
cout<<"输入3个integer: ";
cin>>int1>>int2>>int3;
cout<<"3个int型变量的结果是:"<<maximum(int1,int2,int3)<<endl;

float float1,float2,float3;
cout<<"输入3个单精度数:";
cin>>float1>>float2>>float3;
cout<<"3个float的结果:"<<maximum(float1,float2,float3)<<endl;
return 0;

}