|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
主文件
#include<iostream>
#include "header.h"
int main()
{
using namespace std;
double d[5] = {1.1, 2.2, 3.3, 4.4, 5.5};
int i[5] = {3, 4, 5, 1, 2};
cout << "the max of the int is\t" << max5(i) <<endl;
cout << "the max of the double is\t" << max5(d) << endl;
cin.get();
cin.get();
return 0;
}
函数
#include "header.h"
template<typename T>
typename max5(T num[])
{
T temp = num[0];
int i = 1;
for (; i < Arsize; ++i)
temp = temp > num[i] ? temp : num[i];
return temp;
}
头文件
#ifndef HEADER_H
#define HEADER_H
template<typename T>
typename max5(T num[]);
const int Arsize = 5;
#endif
显示
1>d:\鲁大师\作业\链接\链接\header.h(5): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>d:\鲁大师\作业\链接\链接\2.cpp(12): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1> 1.cpp
1>d:\鲁大师\作业\链接\链接\header.h(5): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1> 正在生成代码... |
|