O'Reilly logo

Sams Teach Yourself C++ in 24 Hours, Third Edition by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Abstract Data Types

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.

Listing 18.3. Shape 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required