<span style="font-size:24px;"><span style="font-size:24px;">#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;
template <typename T,int N>
void fn()
{
T array[N] = {0};
for(int i=0;i<N;i++)
{
array[i] = i+1;
cout << array[i] << " ";
}
cout << endl;
}
int main()
{
fn<int,10>();
fn<float,20>(); //可以动态调整数组大小 ,真棒
return 0;
}</span></span>
一个很牛逼的求和程序!!!转载的
<span style="font-size:24px;">#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;
template <int N>
class Sum
{
private:
public:
static const int Value = Sum<N-1>::Value + N;
protected:
};
template <>
class Sum<1>
{
public:
static const int Value = 1;
};
int main()
{
cout << "求100内的和为 " << Sum<100>::Value <<endl;
return 0;
}</span>