
CSCI-1200 Computer Science II — Spring 2006
Lecture 18 — Templated Classes and Vectors
Test 3 — General Information
•Test 3 will be held Tuesday, April 11th, 2006 10-11:50am, West Hall Auditorium. No make-ups will
be given except for emergency situations, and even then a written excuse from the Dean of Students office will
be required.
•Coverage: Lectures 1-19, Labs 1-10, HW 1-7.
•Closed-book and closed-notes except for 1 sheet of 8.5x11 inch paper (front & back) that may be handwritten
or printed. Computers, cell-phones, palm pilots, calculators, PDAs, etc. are not permitted and must be turned
off.
•All students must bring their Rensselaer photo ID card.
•Practice problems are available on the course website. An optional review session will be held on Sunday
April 9th, from 7-9pm in DCC 324. Bring your questions!
Review from Lecture 17
•Arrays and pointers
•Different types of memory (“automatic”, static, dynamic)
•Dynamic allocation of arrays
18.1 Today’s Lecture
•Designing our own container classes:
–Mimic the interface of standard library containers
–Study the design of memory management code and iterators.
–Move toward eventually designing our own, more sophisticated classes.
•Vector implementation
•Templated classes
•Copy constructors, assignment operators and destructors
18.2 Vector Public Interface
•In creating our own version of the vector class, we will start by considering the public interface:
public:
// Member functions and other operators
T& operator[] (size_type i);
const T& operator[] (size_type i) const;
void push_back(const T& t);
void clear();
bool empty() const;
iterator erase(iterator p);
size_type size() const;
void resize(size_type n);
public:
// Iterator operations
iterator begin();
const_iterator begin() const;
iterator end();
const_iterator end();
•This appears to be quite simple and in fact it is. We will focus on each piece, but especially on the use of
templates, on the underlying representation, and on memory management.