CPP Programming
About Lesson
//Example showing how virtual function solving the reference problem in previous program 
#include<iostream>
using namespace std;

class parent
{
public:
void display(){cout<<“Definition of regular member function in parent class”<<endl; }
void virtual show(){cout<<“Definition of virtual member function in parent class”<<endl;}
};

class child:public parent
{
public:
void display(){cout<<“Definition of regular member function in child class”<<endl; }
void show(){cout<<“Definition of virtual member function in child class”<<endl;}
};

int main()
{
parent p; child c; parent *ptr;
ptr=&p;

ptr->display();
ptr->show();
cout<<endl;
ptr=&c;
ptr->display();
ptr->show();
}


You cannot copy content of this page