

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


#include
int decrement(int a) { cout<<"In Derived2 \n"; return --a; } int derv2_function(int a) { cout<<"In Derived2 \n"; return a; } ~Derived2() { cout<<"Derived2 is now destructed \n"; } }; void main() { Base* ptr; //Base Starts ptr = new Base; cout<<ptr->base_function(-5)<<endl; cout<<ptr->increment(3)<<endl; delete ptr; //Base Ends //Derived1 Starts ptr = new Derived1; cout<<ptr->base_function(-5)<<endl; cout<<ptr->increment(2)<<endl; cout<<ptr->decrement(4)<<endl; delete ptr; //Derived1 Ends //Derived2 Start ptr = new Derived2; cout<<ptr->increment(3)<<endl; cout<<ptr->base_function(98)<<endl; cout<<ptr->decrement(54)<<endl; //ptr->derv2_function(3); Not visible delete ptr; //Derived2 Ends Derived1* ptr2; //Derived1 Starts