Introduction to OOP | Chapter 14: Polymorphism and Software Reuse: | next | previous | audio | real | text |
Everything must be redefined, but implementation can make use of the list data structure.
class Set { public: void add(int); int includes(int); void remove(int); int firstElement(); private: List data; }; | void Set::add (int x) { if (! data.includes(x)) data.add(x); } int Set::includes (int x) { return data.includes(x); } void Set::remove (int x) { data.remove(x); } int Set::firstElement () { return data.firstElement(); } |