kab女装具体叫什么品牌:模板函数的应用,看看哪错了

来源:百度文库 编辑:高校问答 时间:2024/04/29 18:31:50
#include"iostream.h"
void main()
{
template <class T>
T max(T x,T y)
{
return (x>y)?x:y;
};
cout<<max(5,3)<<endl;
}

函数定义不能嵌套
that is function definition can not be nested. For example,
void foo() {
void goo() {
// ...
}
}

You should at least code like this:

#include<iostream.h>

// template function definition

template<class T>
T max(T x, T y) {
return (x > y) ? x : y;
}

void main()
{
cout << max(5,3) << endl;
}