CMPT 212
Fall 1997
|
class Point { public: ... virtual display(); ... }; class Circle : public Point { public: ... virtual display(); ... }; class Disk : public Circle { public: ... virtual display(); ... };
Point * graphobjs[10]; ... for (int i=0; i<10; i++) { graphobjs[i]->display(); }
derivedClass * d = new derivedClass; baseClass * b = d; delete b;
class baseClass { public: virtual ~baseClass(); ... }; class derivedClass : public baseClass { public: virtual ~derivedClass(); ... };
class animal { public: virtual void eat() = 0; ... };
class animal { public: virtual void move() = 0; virtual void breathe() = 0; virtual void eat() = 0; ... };Each class derived from animal must implement these functions, but since different animals move, breathe, and eat in different ways, they can implmenent them in different ways.
Return to lecture notes index |
|
This page is maintained by simpson@cs.sfu.ca. | Last updated on 3 Nov 1997. |