Preview:
#include <iostream>

using namespace std;

class Base{
   
    public:
    virtual void output(){
        cout<<"Virtual Function"<<endl;
    }
    void display(){
        cout<<"Display Base Function"<<endl;
    }
};

class derived:public Base{
    
    public:
    void output(){
        cout<<"Function in the derived "<<endl;
    }
    void display(){
        cout<<"Display Derived Function"<<endl;
    }
};


int main() {
    
    Base *ptr;
    derived d;
    ptr = &d;
  //Run time binding, it will call output function in the drived class
    ptr->output();
  
  //Compile time binding, it will call display function in the base class.
    ptr->display();

    return 0;
}
//OUTPUT:
Function in the derived 
Display Base Function
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter