File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ An **abstract class** in C++ is a class that **cannot be instantiated**. It is u
3030
3131``` cpp
3232#include < iostream>
33+ #include < memory>
3334using namespace std ;
3435
3536// Abstract class
@@ -39,6 +40,7 @@ protected:
3940public:
4041 Vehicle(string b) : brand(b) {}
4142 virtual void start() = 0; // Pure virtual function
43+ virtual ~ Vehicle() = default; // virtual destructor
4244 void displayBrand() {
4345 cout << "Brand: " << brand << endl;
4446 }
@@ -82,11 +84,13 @@ An **interface** in C++ is created using a class that contains **only pure virtu
8284
8385```cpp
8486#include <iostream>
87+ #include <memory>
8588using namespace std;
8689
8790// Defining an interface
8891class Animal {
8992public:
93+ virtual ~Animal() = default; // virtual destructor
9094 virtual void makeSound() = 0; // Pure virtual function
9195};
9296
@@ -150,6 +154,7 @@ Abstraction is widely used in real-world applications, such as payment processin
150154
151155``` cpp
152156#include < iostream>
157+ #include < memory>
153158using namespace std ;
154159
155160// Abstract class for Payment
@@ -158,6 +163,7 @@ protected:
158163 double amount;
159164public:
160165 Payment(double amt) : amount(amt) {}
166+ virtual ~ Payment() = default; // virtual destructor
161167 virtual void pay() = 0; // Abstract method
162168};
163169
You can’t perform that action at this time.
0 commit comments