Lab 2 - Nested Classes of Template Classes

Due: 5:00pm on Wednesday

The purpose of this lab is to see and fix the compiler errors that can be created when attempting to return or declare nested classes objects of template classes.

Log into Sleipnir and create a new directory for this lab. Download the files genericlist2.cpp and lab2main.cpp to that directory. You can download these files using the wget command or by copying the whole file from your browser window and using the command :set paste in vim.

For this lab, the GenericList class from Lab 1 has been augmented with a nested Iterator class. The Iterator class points to a specific element in the array. A search() function has been added to GenericList which will return an Iterator to the element if the element is found in the array (otherwise it returns an Iterator that points to NULL). The run_tests() function now just tests the search() function.

This code will not currently compile because it has not been updated for the new required syntax for nested classes of template classes. Attempt to compile the code as provided so that you can become familiar with the error messages that are produced.

Lab Assignment

Your assignment is to update the code to have the required syntax to declare and return objects of the Iterator class. Anywhere the code refers to GenericList<T>::Iterator, you need to preface that with the typename keyword. This tells the compiler that GenericList<T>::Iterator is a nested class in a template class so that the appropriate syntactical steps are taken to compile the code.

Email me your updated versions of both genericlist2.cpp and lab2main.cpp.