August 2001
Beginner
482 pages
10h 52m
English
Often, you will create a hierarchy of classes together. For example, you might create a Shape class as a base class to derive a Rectangle and a Circle. From Rectangle, you might derive Square as a special case of Rectangle.
Each of the derived classes will override the Draw() method, the GetArea() method, and so forth. Listing 18.3 illustrates a bare-bones implementation of the Shape class and its derived Circle and Rectangle classes.
0: //Listing 18.3. Shape classes. 1: #include <iostream> 2: 3: class Shape 4: { 5: public: 6: Shape(){} 7: virtual ~Shape(){} 8: virtual long GetArea() { return -1; } // error 9: virtual long GetPerim() { return -1; } 10: virtual void Draw() {} 11: }; 12: 13: class ... |
Read now
Unlock full access