Method interface -- list
OOP
template< class E >
class nil : public list< E > { nil
public:
nil() {}
bool empty() { return 1; }
E head() { require( false ); return E(); }
list< E >* tail() { require( 0 ); return 0; }
bool operator==(list* m) { return m->empty(); }
};
template< class E >
class cons : public list< E > { cons
public:
cons(E e, list* l) : _e(e), next(l) {}
~cons() { delete next; }
bool empty() { return 0; }
E head() { return _e; }
list* tail() { return next; }
bool operator==(list* m);
protected:
E _e;
list* next;
};
slide: Data abstraction and objects