// C++ function template example with value and type parameters #include using namespace std; // return pointer to new heap array with N copies of val (not quite // realistic, but shows what’s possible -- better example would be a // template whose non-type parameter specifies the size of a // fixed-size queue or list in a class) template T* valarray(const T &val) { T* a = new T[N]; for (int i = 0; i < N; ++i) a[i] = val; return a; } int main(int argc, char **argv) { int *ip = valarray(17); string *sp = valarray("hello"); delete[] ip; delete[] sp; return 0; }