SDSU CS 596 OODP
New Template Slide

[To Lecture Notes Index]
San Diego State University -- This page last updated Sept 26, 1995
----------


Template (Generic) Functions

C++ Only

template <class MyType>
MyType min( MyType a, MyType b) {
	return a < b ? a : b;
}


main() {
	int a = 1, b = 2;
	float c = 1.1, d = 2.2;
	int e[10], f[10];
	Point Start(1,1), Stop(3.2, 10);

	cout 	<< min( a,b ) 		// prints 1
		<< "\n"
		<< min( c,d )		// prints 1.1
		<< "\n"
		<< min( Start, Stop ) 
		<< "\n"
		<< min( e, f );	//  no < operator on arrays
				//  compile error (I hope)

}


Template functions can be overloaded

Added after AT&T V2 of C++