函数重用和函数引用结合测试
来源:互联网 发布:淘宝大学商学院杭州 编辑:程序博客网 时间:2024/06/08 13:33
#include<iostream>
#include<string>
using namespace std;
template <typename Any>
Any maxn(const Any *p, int n);
template<> string maxn<string>(const string *p, int n);
int main()
{
int arr[7] = { 1,5,24,423,123,14,53 };
double dor[4] = { 3245.325,23523.423,1245.435,1245 };
string str[6] = { "fajsfhsdgh","fakjsgjhfdhur","absdfhbdsguer","fsahgjdsiairng","fasjgjsirhb","fakjsghur" };
int max = 0;
double maxi = 0.0;
string maxchar;
max = maxn(arr, 7);
maxi = maxn(dor, 4);
maxchar = maxn(str, 6);
cout << max << endl;
cout.setf(ios_base::fixed);
cout.precision(5);
cout << maxi << endl;
cout << maxchar << endl;
cin.get();
cin.get();
return 0;
}
template <typename Any>
Any maxn(const Any *p, int n)
{
Any max = p[0];
for (int i = 1;i < n;i++)
{
if (p[i] > max)
max = p[i];
}
return max;
}
template<> string maxn<string>(const string *p, int n)
{
string pf;
int max = 0;
for (int i = 0;i < n;i++)
if (p[i].size() > max)
{
max = p[i].size();
pf = p[i];
}
return pf;
}
#include<string>
using namespace std;
template <typename Any>
Any maxn(const Any *p, int n);
template<> string maxn<string>(const string *p, int n);
int main()
{
int arr[7] = { 1,5,24,423,123,14,53 };
double dor[4] = { 3245.325,23523.423,1245.435,1245 };
string str[6] = { "fajsfhsdgh","fakjsgjhfdhur","absdfhbdsguer","fsahgjdsiairng","fasjgjsirhb","fakjsghur" };
int max = 0;
double maxi = 0.0;
string maxchar;
max = maxn(arr, 7);
maxi = maxn(dor, 4);
maxchar = maxn(str, 6);
cout << max << endl;
cout.setf(ios_base::fixed);
cout.precision(5);
cout << maxi << endl;
cout << maxchar << endl;
cin.get();
cin.get();
return 0;
}
template <typename Any>
Any maxn(const Any *p, int n)
{
Any max = p[0];
for (int i = 1;i < n;i++)
{
if (p[i] > max)
max = p[i];
}
return max;
}
template<> string maxn<string>(const string *p, int n)
{
string pf;
int max = 0;
for (int i = 0;i < n;i++)
if (p[i].size() > max)
{
max = p[i].size();
pf = p[i];
}
return pf;
}
0 0
- 函数重用和函数引用结合测试
- PHP的代码重用和函数编写
- python函数引用传递测试
- 引用函数和非引用函数
- 函数指针和引用
- PHP:引用和函数
- 引用和函数重载
- 函数的重用
- C++引用:经典例题之引用作为函数的返回值,结合函数栈帧详解
- 函数指针和函数引用的区别
- 函数指针和函数引用的区别
- 函数模板和模板函数(引用)
- 函数模板和模板函数(引用)
- 函数指针和函数引用的使用
- 函数指针和函数引用(转载)
- c++引用和引用作为函数参数
- 引用和拷贝构造函数
- 引用和拷贝构造函数
- C/C++知识点
- NSString中initWithString和initWithFormat的区别
- 软件测试目的
- uclinux 与 linux的区别
- oc集合类的创建
- 函数重用和函数引用结合测试
- git 常用命令整理
- 基于rails的schedule网站开发(8):撤销操作
- ASP.NET中使用UpdatePanel实现局部异步刷新方法和攻略
- zzuli 1068《二进制数》
- 字符转整型
- javascript下的DOM命令:css,href,arc
- 使用Opatch给oracle打补丁
- 黑马程序员——集合笔记