









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An in-depth exploration of object-oriented programming (oop) concepts, focusing on abstract classes, pure virtual functions, and virtual destructors in c++. Learn how abstract classes implement abstract concepts, cannot be instantiated, and are used for inheriting interfaces and/or implementation. Discover the role of pure virtual functions in making a class abstract and the difference between abstract and concrete classes. Additionally, explore the concept of virtual destructors and their impact on base class destructors when delete operator is applied to a base class pointer.
Typology: Slides
1 / 17
This page cannot be seen from the preview
Don't miss anything!










►
►
►
►
► ►
►
►
class Shape {
class Shape {
…
…
public:public:
virtual void draw() = 0;
virtual void draw() = 0;
…
…
Shape s;Shape s; // Error!// Error!
docsity.com
Shape
Line Circle Quadrilateral
draw = 0
draw draw
Rectangle
class Quadrilateral : public Shape { class Quadrilateral : public Shape {
public: public:
~Quadrilateral() {
~Quadrilateral() {
cout <<
cout << “
Quadrilateral destructor
Quadrilateral destructor
called
*called *
n
n ”
►
►
class Quadrilateral : public Shape { class Quadrilateral : public Shape {
public: public:
virtual ~Quadrilateral() {
virtual ~Quadrilateral() {
cout <<
cout << “
Quadrilateral destructor
Quadrilateral destructor
called
*called *
n
n ”
►
►
docsity.com
►
►
Shape
Shape
calcArea
draw
Shape vTable
… draw
Line vTable
calcArea
Line object
Shape …
point1 = p
point2 = p
Memory overhead due to vTables
Memory overhead due to vTables
Processing overhead due to extra pointerProcessing overhead due to extra pointer
manipulation
manipulation
►
►