专题博客链接
原题题目
#include <iostream>
#include <string>
using namespace std;
template <class T>
T SumArray(
// 在此处补充你的代码
}
int main() {
string array[4] = { "Tom","Jack","Mary","John"};
cout << SumArray(array,array+4) << endl;
int a[4] = { 1, 2, 3, 4}; //提示:1+2+3+4 = 10
cout << SumArray(a,a+4) << endl;
return 0;
}
代码实现
没搞懂什么叫不能编写SumPrint函数 😦
// 在此处补充你的代码
T* a,T* b)
{
int tempcount = 0;
T* temp;
T ret;
for(temp = a;temp != b;temp++,tempcount++)
{
if(!tempcount) ret= *temp;
else ret = ret + *temp;
}
return ret;