/*--------------------------------------- * File name : exampone.cpp * Author: Xiannong Meng * Date: April 2, 1997 * Assignment: Classroom demonstration * Problem statement: This is a simple program to demonstrate * how function templates work in C++. *-------------------------------------- */ #include // a simple template function, T is a 'dummy' type // the actual type will be assigned when the function // is called. template void f(int a, T i[]) { cout << a << " template f(): " << i[a] << endl; } int main() { // define some different arrays int a[] = {2, 4, 6}; // array of integers char b[] = {'a', 'b', 'c'}; // array of characters char d[] = {'e', 'f', 'g', 'h'}; float c[] = {0.2, 2.3, 5, 7}; // array of float f(1,a); // apply function to integer f(2,b); // apply function to character f(2,d); // a different character array f(3,c); // apply function to float return 0; }