Thu Nov 13, 2008 8:11 pm
#include <iostream>
using namespace std;
template <class X> X sum(X *data, int size)
{
int i;
X result = 0;
for(i = 0; i <size; i++) result += data[ i ];
return result;
}
int main()
{
int i[] = {1, 2, 3, 4};
double d[] = {1.1, 2.2, 3.3, 4.4};
cout << sum(i, 4) << endl;
cout << sum(d, 4) << endl;
return 0;
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.