CIS29 - Notes for 11/5

Announcements

Topic - Class Templates

A class template is a class definition that contains a generic type, and one or more function templates. Just like function templates, instantiations of a class template are called template classes. Class templates are most commonly used with container classes.

  1. The first class template example
  2. The second example - a class template with arrays
  3. The third example - class templates with container & iterator classes
  4. The fourth example - A generic File I/O Class
  5. The fifth example - A generic Linked List

Clarification of Homework Assignment 5

Lab Exercise 13

Finish this program:

template <typename T, typename U>
class TWO
{
	T one;
	U two;
public:
	?
	?
	?
};


int main()
{
	TWO<int, double> object1(5,6.7);
	TWO<string, unsigned int> object2("Have a nice day",4u);
	TWO<string, string> object3("apple","banana");
	TWO<string, string> object4("cantaloupe","date");
	TWO< TWO<string, string>, TWO<string, string> > object5(object3, object4);

	cout << object1.first() << ' ' << object1.second() << endl;
	?
	?
	?
	?
}

Program output:

5 6.7
Have a nice day 4
apple banana
cantaloupe date
apple banana cantaloupe date