#include <iostream>
using namespace std;

class Base
{

   public:
   Base()
   {
      cout<<"Constructor BAse is called"<<endl;
       //function1();
   }

   virtual void function1()
   {
       cout<<"Base function is called"<<endl;
       //function1();
   }

   virtual ~Base()
   {
      cout<<"Destructor Base is called"<<endl;
   }

};


class Derived1 : public Base
{
    //Base *b;
    public:
    Derived1()
    {
      cout<<"Constructor Derived is called"<<endl; 
        //function1();
    }

   void function1()
   {
       cout<<"Derived function is called"<<endl;
       //function1 //out of bounds
       // b = new Derived1();
       // b->function1();
       
   }

   virtual ~Derived1()
   {
      cout<<"Destructor Derived is called"<<endl;
   }


};

int main() {

    Base *b = new Derived1();
     b->function1();
    //Derived1 d;
    //d.function1();
    delete b;
    
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: