

























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


























class Shape {
…
public:
virtual void draw() = 0;
} …
Shape s; // Error!
class Quadrilateral : public Shape { … // No overriding draw() method } … Quadrilateral q; // Error!
class Rectangle:public Quadrilateral{ … public: // void draw() virtual void draw() { … // function body } } … Rectangle r; // OK
class Quadrilateral : public Shape {
… public: ~Quadrilateral() { cout << “Quadrilateral destructor called\n”; }
}
class Rectangle : public Quadrilateral { … public: ~Rectangle() { cout << “Rectangle destructor called\n”; }
}
int main() {
Shape* pShape = new Rectangle(); delete pShape; return 0;
}
Shape destructor called
Shape Part
Quad Part
Rect Part
pShape
Quad Part Rect Part
pShape
class Quadrilateral : public Shape {
… public: virtual ~Quadrilateral() { cout << “Quadrilateral destructor called\n”; }
}
class Rectangle : public Quadrilateral { … public: virtual ~Rectangle() { cout << “Rectangle destructor called\n”; }
}