DEV Community

Alexander Crescent
Alexander Crescent

Posted on

Answer: When to use virtual destructors?

A virtual constructor is not possible but virtual destructor is possible Let us experiment.......

#include <iostream>

using namespace std;

class Base
{
public:
    Base(){
        cout << "Base Constructor Called\n";
    }
    ~Base(){
        cout << "Base Destructor called\n";
    }
};

class Derived1: public Base
{
public:
    Derived1(){
        cout << "Derived constructor called\n";

Top comments (0)